Johnny C
Well-known Member
- Joined
- Nov 7, 2006
- Messages
- 1,069
- Office Version
- 365
- Platform
- Windows
I've been idling a dull afternoon away tidying up some VBA that works on ranges using the Evaluate function. More out of curiosity than anything else. I'm keen to understand it, I once came across a piece of horrible spaghetti code that used [Sum(Indirect(formula))] and I just gave up at that point and rewrote it but it would be nice to be able to decipher it.
This works, it trims a whole range of text without a loop:
but when I tried to use the [] form it returns a #NAME ! error
Debug.Print shows it's giving an error 2029, the same if I remove the quotes
Rng.Value = [if(row(),Trim(Rng.Address))]
I'm guessing I've not got the hang of the syntax of the [] form, what should I put?
This works, it trims a whole range of text without a loop:
Code:
Sub TrimData()
Set Rng = Selection
Rng.Value = Evaluate("if(row(),Trim(" & Rng.Address & "))")
End Sub
but when I tried to use the [] form it returns a #NAME ! error
Code:
Sub TrimData2()
Set Rng = Selection
Rng.Value = ["if(row(),Trim(" & Rng.Address & "))"]
End Sub
Debug.Print shows it's giving an error 2029, the same if I remove the quotes
Rng.Value = [if(row(),Trim(Rng.Address))]
I'm guessing I've not got the hang of the syntax of the [] form, what should I put?
Last edited: