Is this what you are trying? I am showing an example for Column B
. Do it for the rest.
Logic:
- Find Last Row in a Column. See THIS
- Construct your range
- Format the range as required.
Code:
Private Sub Sample()
Dim ws As Worksheet
Dim LastRow As Long, Header As Long
Header = 5 '<~~ Start row for formatting
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
LastRow = .Range("B" & .Rows.Count).End(xlUp).Row
With .Range("B" & Header & ":B" & LastRow)
'
'~~> Change format here
'
'~~> Number with 5 decimal places.
.NumberFormat = "0.00000"
End With
End With
End Sub
FOLLOWUP FROM COMMENTS
Thanks but this just formatting the B5 cell, can you please let me know how i can do the rest of rows from 5 to like 1000 – Behseini 11 secs ago
Oh so if there are no values after row 5 and you want to hardcode the last row then use this code
Private Sub Sample()
Dim ws As Worksheet
Dim LastRow As Long, Header As Long
Header = 5 '<~~ Start row for formatting
LastRow = 1000 '<~~ Last Row
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
With .Range("B" & Header & ":B" & LastRow)
'
'~~> Change format here
'
'~~> Number with 5 decimal places.
.NumberFormat = "0.00000"
End With
End With
End Sub