Hi i am Very new to vba, first day using it, im trying to get the following code to read down the list and remove all the letter and spaces so i am just left with number in the column to the right. this code is something that i found on line and am trying to edit for my own purposes, any help would be greatly aprecated. i am still googling franticly to see what i can find. i get the error on line starting 'For each cell'
Sub Remove_Alphabets_SpecialChar_RetainDecimalNumber_Test()
Dim RegX As Object
Dim Rng As Range
Set RegX = CreateObject("vbscript.regexp")
With RegX
.Global = True
.Pattern = "[^-0-9-.]"
End With
Range(Range("d4").End(xlDown)).Select
For Each cell In Range(Selected)
Rng.Offset(, 1) = RegX.Replace(Rng, "")
Next cell
End Sub
Selected
has not been defined. You need this to be a range object e.g.Set rng = Range("A1:A10")
orRange("D" & Range("D4").End(xlDown).Row
– Alex PDim rng as Range
. Then you need to define the range object (e.g.Set rng = Range("A1:A10")
) anywhere before thefor...each
loop. – Alex P