Reputation: 9
Sub FormatThreeDecimals()
Dim ws As Worksheet
Dim rng As Range
Dim lastCell
Set ws = Worksheets("Summary")
lastCell = Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious).Select
Set rng = [B4:LastCell]
Range("rng").NumberFormat = "0.000"
End Sub
I want define the range B4:lastCell with the variable rng, then apply "0.000" Number Format to it. I am having issues setting the range properly.
Edit: I receive Run-time error '424': Oject required when my code hits the line Set rng = [B4:LastCell].
Upvotes: 0
Views: 186
Reputation: 12279
Try this:
Dim lastCell As Range
Set ws = Worksheets("Summary")
Set lastCell = ws.Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious)
Set rng = ws.Range("b4", lastCell)
rng.NumberFormat = "0.000"
Upvotes: 1