Column Colors

cr2289

New Member
Joined
Jul 21, 2016
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Help please. I have a spreadsheet where certain columns need to be highlighted. The columns are empty. I just need to change the color. I need the macro because I'll be using it on different spreadsheets and the number of rows will change. Essentially, what's a macro that will highlight a column to the end of the rows with values?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Help please. I have a spreadsheet where certain columns need to be highlighted. The columns are empty. I just need to change the color. I need the macro because I'll be using it on different spreadsheets and the number of rows will change. Essentially, what's a macro that will highlight a column to the end of the rows with values?

you did not specify which color.

this code asks the user to select the first cell in the column they want the color to start in
it then determines the last row of data in that column
it then colors all cells red.

Code:
Sub cr2289()

Dim wb As Workbook
Dim ws As Worksheet
Dim lngrow As Long
Dim rng As Range
Dim strRNG As String
Set wb = ThisWorkbook
Set ws = ActiveSheet
On Error Resume Next
Set rng = Application.InputBox(Prompt:="Pick the first Cell in the range to be colored", Type:=8)
On Error GoTo 0
If rng Is Nothing Then
    MsgBox "user did not choose a cell"
    Exit Sub
End If
With ws
    lngrow = Cells(ws.Rows.Count, rng.Column).End(xlUp).Row
    Set rng = ws.Range(ws.Cells(rng.Row, rng.Column), ws.Cells(lngrow, rng.Column))
    rng.Interior.color = 255
End With
End Sub
 
Upvote 0
Thank you for the reply! I should have provided a better example.

I'd like to change the color of Columns N, P, R, U to light blue beginning with the header row (Row 1) down to the last row with values. Except for headers, the columns have no values entered.
 
Upvote 0
Try this, but it would be just as quick doing it manually

Code:
Sub MM1()
Dim lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
Range("N1:N" & lr).Interior.Color = 15773696
Range("P1:P" & lr).Interior.Color = 15773696
Range("R1:R" & lr).Interior.Color = 15773696
Range("U1:U" & lr).Interior.Color = 15773696
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,572
Members
448,972
Latest member
Shantanu2024

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