I have a table linked to a SQL database that I use to create some reports. The problem is that the numbers come as text and I have to convert them to numbers everytime, I\'v
xlDown
can be highly unpredictive. Don't use that. In fact find the last row and then create your range and then use that for your operations.
Also just changing the format will not convert those to number. You will have to replicate the F2-Enter
behavior.
Try this (TRIED AND TESTED)
Sub Sample()
Dim ws As Worksheet
Dim Rng As Range, acell As Range
Dim lRow As Long
Set ws = ThisWorkbook.Sheets("Sheet1")
With ws
lRow = .Range("AC" & .Rows.Count).End(xlUp).Row
Set Rng = .Range("A4:AC" & lRow)
.Range("B2").Copy
Rng.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlMultiply, SkipBlanks:=False, Transpose:=False
Rng.NumberFormat = "0" ' OR "0.00" as applicable
For Each acell In Rng
acell.Formula = acell.Value
Next
End With
End Sub
SCREENSHOT