code restructure

zrx1200

Well-known Member
Joined
Apr 14, 2010
Messages
622
Office Version
  1. 2019
Platform
  1. Windows
Code:
Public Sub End_of_day_color_row()
     Dim LastRowColA As Integer
      Dim worksht As String
         LastRowColA = Range("B65536").End(xlUp).row

      With Worksheets("Newidea").Range("S16")
           .Range(.Cells(LastRowColA, 2), _
            .Cells(LastRowColA, 1)).EntireRow.Interior.Color = RGB(255, 140, 0)
      End With
End Sub

I wish to color last none used row orange at the end of day. Just need to get this to work correctly. Its picking last row correctly but can get entire row to color?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Maybe this...

Code:
Public Sub End_of_day_color_row()
Dim LastRowColA As Long
LastRowColA = Range("B65536").End(xlUp).Row
Worksheets("Newidea").Rows(LastRowColA).Interior.Color = RGB(255, 140, 0)
End Sub
 
Upvote 0
Latest revision. Thanks Sir!

Code:
Public Sub End_of_day_color_row()
        Dim LastRowColA As Long
        Dim worksht As String
          worksht = Worksheets("Newidea").Range("S16")
     LastRowColA = Range("B65536").End(xlUp).row
       Worksheets(worksht).Rows(LastRowColA).Offset(1, 0).Interior.Color = RGB(255, 140, 0)
End Sub
 
Upvote 0
there is no need for Range("S16")

Code:
Public Sub End_of_day_color_row()
Dim LastRowColA As Long, worksht As Worksheet
Set worksht = Worksheets("Newidea")
LastRowColA = Range("B65536").End(xlUp).Row
worksht.Rows(LastRowColA).Offset(1, 0).Interior.Color = RGB(255, 140, 0)
End Sub
 
Upvote 0
there is no need for Range("S16")

Code:
Public Sub End_of_day_color_row()
Dim LastRowColA As Long, worksht As Worksheet
Set worksht = Worksheets("Newidea")
LastRowColA = Range("B65536").End(xlUp).Row
worksht.Rows(LastRowColA)[B][COLOR="#FF0000"].Offset(1, 0)[/COLOR][/B].Interior.Color = RGB(255, 140, 0)
End Sub
There is no need for the Offset function call either... since we have the last row number in a variable, we can just add one to it directly...

worksht.Rows(LastRowColA + 1).Interior.Color = RGB(255, 140, 0)
 
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,167
Members
448,870
Latest member
max_pedreira

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