Consulting

Results 1 to 9 of 9

Thread: Solved: "Active Row" use in Macro

  1. #1
    VBAX Tutor cmpgeek's Avatar
    Joined
    Jun 2004
    Location
    Athens, Ga USA
    Posts
    204
    Location

    Solved: "Active Row" use in Macro

    How do I change the following coding so that it will highlight the the entire row where the selected cell is located?

    [vba]
    Selection.Insert Shift:=xlToRight
    Rows("42:42").Select
    With Selection.Interior
    .ColorIndex = 6
    .Pattern = xlSolid
    End With
    [/vba]

    I know that Rows("42:42").Select is the problem; I am just not sure what needs to be there so that it highlights the whole row and not just the cell that is selected (if that is possible)...

    Thanks,



    Life is like a jar of jalepenos... What you do with it today might burn your butt tomorrow....

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    See if this helps:
    [VBA]
    Rows("42:42").Rows.EntireRow.Select
    With Selection.Interior
    .ColorIndex = 6
    .Pattern = xlSolid
    End With
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Try this.
    [vba]
    With Rows("42:42").Interior
    .ColorIndex = 6
    .Pattern = xlSolid
    End With [/vba]

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Yep, thats better Norie....no selection necessary. Thanks
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    VBAX Tutor cmpgeek's Avatar
    Joined
    Jun 2004
    Location
    Athens, Ga USA
    Posts
    204
    Location
    the problem is that I don't want it to highlight row 42 every time. That was the row I happened to pick when I initially recorded the macro... I am hoping that if I select a cell and initiate the macro that the macro will move the selected cell to the right 1 block and will then highlight the entire row...

    So if I select B15, it will insert a cell and shift my selected cell over to the right and then highlight all of row 15... (i hope I am explaining this so that it makes sense)...

    is there coding that will affect an entire row even if only one cell within the row is selected?

    thanks yall!



    Life is like a jar of jalepenos... What you do with it today might burn your butt tomorrow....

  6. #6
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Quote Originally Posted by cmpgeek
    the problem is that I don't want it to highlight row 42 every time.
    Kind of thought that might be the case.

    If you just wanted to do this for the row the active cell is in then try this.
    [vba]
    With ActiveCell.EntireRow.Interior
    .ColorIndex = 6
    .Pattern = xlSolid
    End With [/vba]

  7. #7
    VBAX Tutor cmpgeek's Avatar
    Joined
    Jun 2004
    Location
    Athens, Ga USA
    Posts
    204
    Location
    That is just what I was hoping for!!!

    Thank you so much!



    Life is like a jar of jalepenos... What you do with it today might burn your butt tomorrow....

  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    As xlSolid appears to be the default
    [vba]
    ActiveCell.EntireRow.Interior.ColorIndex = 6

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  9. #9
    How about this:
    [vba]Rows("42").Interior.ColorIndex = 6[/vba] I don't understand the benefit of "42:42" when "42" does the job.

Posting Permissions

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