Replace function result captured in variable.

S

shelfish

Could someone offer a quick assist on how to capture the result of the
replace function in a variable rather than in a cell...

***********************************************************************************
Dim Alphabet As Variant
Alphabet = Array("A"..."Z")

Dim model as string
Model = Left(A1,4)

'delete all letters in string
For i = LBound(Alphabet) To UBound(Alphabet)
Replace Expression:=Model, Find:=Alphabet(i), Replace:=""
Model = [capture value from replace function above]
Next

***********************************************************************************

I'm sure I'm making a simple mistake here. Your help is appreciated.

Thanks.
S.
 
R

Rick Rothstein \(MVP - VB\)

This will be quicker than using Replace...

Dim i As Long
Dim Model As String

Model = Left(Range("A1"), 4)

'delete all letters in string
For i = 1 To Len(Model)
If Mid(Model, i, 1) Like "[A-Za-z]" Then
Mid(Model, i) = Chr(1)
End If
Next
Model = Replace(Model, Chr(1), "")

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top