loop

W

Wanna Learn

I created a macro and it works fine, however I want to add a loop. (Hope
that is the term) I want to be able to go to the last row in the worksheet
and highlight the row in grey and make the font bold .
 
D

Dave Peterson

Sometimes you don't need to loop.

If you can pick out a column that always has data when the row is used, you can
use that to find the last row.


Dim LastRow as long
With worksheets("Sheet1")
lastrow = .cells(.rows.count,"X").end(xlup).row
'then format .rows(lastrow)
end with
 
R

RAJ

Tey this:-
Dim rowNum
Dim colNum
rowNum = Range("a1").End(xlDown).Row
colNum = Range("a1").End(xlDown).End(xlToRight).Column

With Range(Cells(rowNum, 1), Cells(rowNum, colNum))
.Font.Bold = True
.Interior.ColorIndex = 15
End With
 
W

Wanna Learn

Thanks Dave
I copied the macro, but it does not work . My last column that always has
data is Q. I am overlooking something , sorry I just don't get it. Please
clarify
 
W

Wanna Learn

Wanna Learn said:
Thanks Dave
I copied the macro, but it does not work . My last column that always has
data is Q. I am overlooking something , sorry I just don't get it. Please
clarify
 
W

Wanna Learn

Dave
I'm in trouble again

Below is the macro I'm using (the one you gave me) BUT instead of
highlighting the last row it highlights and bolds the first row all the way
across to the last column in the spreadsheet. It should stop around column
Q .. thanks

Dim LastRow As Long
With Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "X").End(xlUp).Row
'then format .rows(lastrow)

..Rows(LastRow).Font.Bold = True
.Rows(LastRow).Interior.ColorIndex = 15

End With

End Sub
 
D

Dave Peterson

I used column X to determine the last row. Make sure you change that to a
column that you can depend on having data.



Wanna said:
Dave
I'm in trouble again

Below is the macro I'm using (the one you gave me) BUT instead of
highlighting the last row it highlights and bolds the first row all the way
across to the last column in the spreadsheet. It should stop around column
Q .. thanks

Dim LastRow As Long
With Worksheets("Sheet1")
LastRow = .Cells(.Rows.Count, "X").End(xlUp).Row
'then format .rows(lastrow)

.Rows(LastRow).Font.Bold = True
.Rows(LastRow).Interior.ColorIndex = 15

End With

End Sub
 
W

Wanna Learn

Dave
It works great! Yes once I changed that "X" to the last column with data it
worked.
THanks for making my day!
 
Top