Need macro to select only columns B through W in active cell row

wilkisa

Well-known Member
Joined
Apr 7, 2002
Messages
660
Office Version
  1. 365
  2. 2016
  3. 2013
Platform
  1. Windows
I retired and have been away from Excel for several years. However, my daughter has brought me a problem and I have been able to fix all but the code for this. I need the code to select only cells in the active row in columns B to W, which is 22 cells. Then, color the cells in color index 43. Please note that not all cells are filled so Selection.End(xlToRight)).Select doesn't work because it stops at a blank cell.

I just can't remember how to make this work. Getting too old perhaps?

Any help would be gratefully accepted. It should be easy for the gurus out there.

Thank you so much,
Shirlene
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
The basic bit of code is the 'Range' statement. How you colour is what you need to supply. I just set them to some colours

VBA Code:
Sub aaa()
    Range(Cells(ActiveCell.Row, 2), Cells(ActiveCell.Row, 22)).Select
    With Selection.Font         'Sets the text font
        .Color = -1003520
        .TintAndShade = 0
    End With
    With Selection.Interior     'Sets the fill colour
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 6299648
        .TintAndShade = 0
        .PatternTintAndShade = 0
    End With
End Sub
 
Upvote 0
Solution
Thank you, HIcksi. This fixes the problem. I wasn't using the start as column 2, end as column 23. I was trying to do it in one single selection.

I appreciate your help!
 
Upvote 0
Code:
Sub With_Single_Selection()
    Cells(ActiveCell.Row, 2).Resize(, 22).Interior.ColorIndex = 43
End Sub
 
Upvote 0
Code:
Sub With_Single_Selection()
    Cells(ActiveCell.Row, 2).Resize(, 22).Interior.ColorIndex = 43
End Sub
Thank you, Jolivanes. This is very similar to the change I made using Hicksi's code. I didn't need everything he provided but I just needed the push in the right direction.
 
Upvote 0
Code:
Sub With_Single_Selection()
    Cells(ActiveCell.Row, 2).Resize(, 22).Interior.ColorIndex = 43
End Sub
That is so cool. But does it work because Excel VBA is impure?
Things that are being done reflect a range. But 'Cell' isn't natively a range, but can be converted to one by VBA when needed.
But I gotta say the line is pretty cool.
 
Upvote 0
Another way that some people prefer because it uses the column lettering that is familiar to them

VBA Code:
Sub Test()
  Intersect(ActiveCell.EntireRow, Columns("B:W")).Interior.ColorIndex = 43
End Sub
 
Upvote 0
Another way that some people prefer because it uses the column lettering that is familiar to them

VBA Code:
Sub Test()
  Intersect(ActiveCell.EntireRow, Columns("B:W")).Interior.ColorIndex = 43
End Sub
Is there a book that talks about "cool" excel functions that perform tasks far faster than others?
I have never in my life used INTERSECT. And I know that there are other functions that I have started to use because I saw them used effectively on here. MATCH and OFFSET are definitely amongst those that don't seem to get captured by Record-Macro, and are so useful.
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,451
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top