Domski
Well-known Member
- Joined
- Jan 18, 2005
- Messages
- 7,292
I'm slowly starting to get my head around using the Evaluate function which I've found you can use sometimes instead of looping through cells in a column.
A couple of examples being:
and:
The first I use as a lot of ID's on our SAP system export as text with leading zeroes and I format other data to perform lookups. The second I just wrote to answer a post on here for shortest way to fill a range with 51, 101 , 151, 201 etc and it was the shortest I could think of.
I find it a lot faster than looping through thousands of cells and wondered if anyone else used it much and how.
I have never found much documentation on it and the help file makes little sense to me as to how it should be used.
Dom
A couple of examples being:
Code:
Sub Convert_Pers_Nums()
' formats values in a column as fixed length text string padded with 0's
Dim strFormat As String
Dim intFormat As Integer
intFormat = InputBox("How many characters?")
strFormat = WorksheetFunction.Rept("0", intFormat)
With Selection
.NumberFormat = "@"
.Value = Evaluate("IF(" & .Address & " = """","""",Text(" & .Address & ",""" & strFormat & """))")
End With
End Sub
and:
Code:
Sub Fill_Col()
' fills range with mutliples of n x 50 + 1
With Range("H1:H200")
.Value = Evaluate("Row(" & .Address & ")*50+1")
End With
End Sub
The first I use as a lot of ID's on our SAP system export as text with leading zeroes and I format other data to perform lookups. The second I just wrote to answer a post on here for shortest way to fill a range with 51, 101 , 151, 201 etc and it was the shortest I could think of.
I find it a lot faster than looping through thousands of cells and wondered if anyone else used it much and how.
I have never found much documentation on it and the help file makes little sense to me as to how it should be used.
Dom
Last edited: