+ Reply to Thread
Results 1 to 11 of 11

Macro that will hightlight a cell and four rows to right based on text in cell:

  1. #1
    Registered User
    Join Date
    07-12-2014
    Location
    North Carolina
    MS-Off Ver
    Office 2007
    Posts
    79

    Macro that will hightlight a cell and four rows to right based on text in cell:

    Hello All,
    Here's what I'm trying to accomplish, I hope someone can give me some tips.

    I have a spreadsheet where if Cell A2 says "Deposit", Rows A2-E2 would be formatted with a Blue background.

    I've tried conditional formatting, but I can't built it into a Macro (I can't make it run), and it only highlights the cell that has that value. I also tried having the spreadsheet filter down to only the values I want highlighted, then highlighting all cells and un-filtering the column- this didn't work either.

    Anybody know what code I use?

    It would basically say
    If (any cell in Row A) has text = "Deposit" (it needs to be exact, it can't be "containing"), set cell with the word "Deposit" and 4 cells to the right as Blue (I'm not picky about the color).

    Thanks in advance, I can't beleive how helpful everyone is on this forum!

  2. #2
    Forum Contributor lancer102rus's Avatar
    Join Date
    04-02-2014
    Location
    Ufa
    MS-Off Ver
    Excel 2010, 2013
    Posts
    252

    Re: Macro that will hightlight a cell and four rows to right based on text in cell:

    Why do you need macro? It can be made with CF
    exmpl.xlsx

  3. #3
    Registered User
    Join Date
    07-12-2014
    Location
    North Carolina
    MS-Off Ver
    Office 2007
    Posts
    79

    Re: Macro that will hightlight a cell and four rows to right based on text in cell:

    How it looks is perfect, thanks for posting that.

    My only questions is- is it possible to incorporate applying the conditional
    formatting into a Macro? I'm going to have very non-excel savvy people use this spreadsheet, and I'm concerned that explaining to them how to apply the formatting would be confusing for them. (I know how to build a Macro that will create the conditional formatting in a new sheet, I just can't get it to apply automatically).

    Thanks again,

    Chad

  4. #4
    Forum Contributor lancer102rus's Avatar
    Join Date
    04-02-2014
    Location
    Ufa
    MS-Off Ver
    Excel 2010, 2013
    Posts
    252

    Re: Macro that will hightlight a cell and four rows to right based on text in cell:

    if you want apply CF automatically, set the macro code to Workbook_Open sub

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro that will hightlight a cell and four rows to right based on text in cell:

    Hi, Chad Bateman,

    if you want the result from VBA directly and depending on how the data is changed you should consider the Worksheet_Change-event for direct enter/edit in the cells or Worksheet_Calculate for formula results behind the sheet. And you should narrow down the range where the code should work as well as make sure that macrois are enabled when the workbook is opened.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  6. #6
    Registered User
    Join Date
    07-12-2014
    Location
    North Carolina
    MS-Off Ver
    Office 2007
    Posts
    79

    Re: Macro that will hightlight a cell and four rows to right based on text in cell:

    Lancer102rus,
    I can't get the Workbook_Open sub to work. I took the Macro I built that created the CF rules, and added "Private Sub Workbook_Open(), to the beginning, and tried running it. That didn't work. Again, it's creating the rules, but not executing them. Also, the CF rules don't want to keep the cells I'm applying them to saved (I checked the Macro Code to ensure the correct cells were selected, but it keeps defaulting to a different set of cells). I can't record a Macro to set the cells correctly.

    Anyways, I've been trying the conditional formatting way for hours. Do you have any idea how I can use some VBA code instead? I don't really know how to build it, I'm usually able to find something similar online, and modify to my needs as necessary.

    Thanks again,

    Chad

  7. #7
    Registered User
    Join Date
    07-12-2014
    Location
    North Carolina
    MS-Off Ver
    Office 2007
    Posts
    79

    Re: Macro that will hightlight a cell and four rows to right based on text in cell:

    HaHoBe,
    Thanks for the tips. Do you have any similar code I can mess around with and try to repurpose?

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro that will hightlight a cell and four rows to right based on text in cell:

    Hi, Chad Bateman,

    code goes behind the sheet:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  9. #9
    Registered User
    Join Date
    07-12-2014
    Location
    North Carolina
    MS-Off Ver
    Office 2007
    Posts
    79

    Re: Macro that will hightlight a cell and four rows to right based on text in cell:

    This is probably a dumb question...does "behind the sheet" mean in the "source" section of the particular tab? Should I enter it into by adding a new module in the Visual Basic screen? Can I just copy and paste it into a different Macro that's not set to private?

    Thanks for your patience,

    Chad

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Macro that will hightlight a cell and four rows to right based on text in cell:

    Hi, Chad ,

    right-click worksheet-tab, choose View Code paste into teh code window (taht´s behind the sheet as you may notify if you look at the Project Explorer). Code won´t run when placed in a standard module (or ThisWorkbook).

    Ciao,
    Holger

  11. #11
    Registered User
    Join Date
    07-30-2014
    Location
    india
    MS-Off Ver
    2007
    Posts
    43

    Re: Macro that will hightlight a cell and four rows to right based on text in cell:

    hi chad run the code included in file sol2
    Attached Files Attached Files
    Last edited by globalsourcing; 08-07-2014 at 02:20 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to Show/Hide Rows Based on Text in Cell
    By HCopeland3 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-01-2014, 03:56 PM
  2. [SOLVED] Macro to search rows for specific text within a cell then cut cell to specified location
    By jonathanpotts90 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-25-2012, 06:18 AM
  3. Macro for hiding rows based on text in a given cell
    By greeneggsandsam in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-27-2012, 05:17 PM
  4. Macro that will clear contents of cell based on format of text in adjacent cell
    By judasdac in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-12-2012, 01:56 AM
  5. Replies: 16
    Last Post: 01-19-2012, 08:18 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1