+ Reply to Thread
Results 1 to 6 of 6

Highlighting multiple rows through a worksheet depending a cell value in the rows

  1. #1
    Registered User
    Join Date
    02-08-2014
    Location
    South africa
    MS-Off Ver
    Excel 2010
    Posts
    3

    Highlighting multiple rows through a worksheet depending a cell value in the rows

    Hi, I am new to this and macros.
    Been messing around a bit and achieved quite a lot already without help, but now I am stuck.
    I know I am doing things the long way but that's because of my limited understanding of the code,
    what I am trying to do is every time I click the worksheet the macro must run and check a cell value and if the cell value is emtpy it must highlight the entire row(no probs can do this),
    but I have to do this for each row, 300 hundred of them and I am using the same code multiple times so I get the error "compile error: procedure to large".
    I do not know how to split the code so that its smaller but then both sets of code run when the sheet is activated and I do not know how to make the code itself shorter so there is no need to split it.
    Any help u can offer will be greatly appreciated.
    This is the code.

    Private Sub Worksheet_Activate()
    If Sheets("Players").Range("K5") = "" Then
    Sheets("Players").Range("B5:J5").Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 5296274
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    End If
    If Sheets("Players").Range("K6") = "" Then
    Sheets("Players").Range("B6:J6").Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 5296274
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    End If
    all the way through to
    If Sheets("Players").Range("K300") = "" Then
    Sheets("Players").Range("B300:J300").Select
    With Selection.Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .Color = 5296274
    .TintAndShade = 0
    .PatternTintAndShade = 0
    End With
    End If

    End Sub

    Don't laugh, took ages and thought I was very cleaver to figure out the code lol. Just a pity it to long to work.

  2. #2
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: Highlighting multiple rows through a worksheet depending a cell value in the rows

    Hi,

    Welcome to the forum

    Actually, you can do this without a macro. Believe it or not, the built in tools of Excel are usually more optimal than macros.
    See the image for an illustration of how you can set up Conditional Formatting to do this on your sheet.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by RudiS; 04-18-2014 at 05:10 PM.
    Regards,
    Rudi

  3. #3
    Registered User
    Join Date
    02-08-2014
    Location
    South africa
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Highlighting multiple rows through a worksheet depending a cell value in the rows

    lol. Ok then. That was easy, I guess it pays to ask.
    Thanks for the info ,the answer and the welcome.

  4. #4
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: Highlighting multiple rows through a worksheet depending a cell value in the rows

    Happy to assist.

    BTW: If you were interested in code, you would need a loop or a filter involved that will allow for many rows to be processed at once without that duplicated code.

  5. #5
    Registered User
    Join Date
    02-08-2014
    Location
    South africa
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Highlighting multiple rows through a worksheet depending a cell value in the rows

    Thanks, RudiS.
    While I have u attention is there any way to make a sheet name reference a cell in another sheet cause this is another thing I have not been able to get right.

  6. #6
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: Highlighting multiple rows through a worksheet depending a cell value in the rows

    Hi,

    You can use the same conditional formatting to do this, but just change the rule to a formula instead.
    See the illustration and the sample workbook.
    Attached Images Attached Images
    Attached Files Attached Files

+ 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. VBA Macro to hide rows depending on the cell value - Can I do this multiple times?
    By Ndocksey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2013, 09:00 AM
  2. [SOLVED] Move rows into worksheet depending on cell value with header row
    By meanger in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2013, 10:52 AM
  3. [SOLVED] Insert multiple rows depending on cell value
    By AR-51 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-03-2013, 04:18 AM
  4. [SOLVED] Highlighting duplicate rows on 2 sheets depending on Value of cell
    By BullseyeThor in forum Excel General
    Replies: 3
    Last Post: 11-16-2012, 12:00 PM
  5. [SOLVED] Move rows into worksheet depending on cell value
    By mattmac in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-17-2012, 04:17 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