range.address, replace characters
You are missing some arguments for the Replace Function:
expression.Replace(Arg1, Arg2, Arg3, Arg4)
expression Required. An expression that returns a WorksheetFunction object.
Arg1 Required String. Text in which you want to replace some characters.
Arg2 Required Double. The position of the character in Arg1 that you want
to replace with Arg4.
Arg3 Required Double. The number of characters in Arg1 that you want the
Replace method to replace with Arg4.
Arg4 Required String. Text that will replace characters in Arg1.
"Rick S." wrote:
I am having dificulties cyphering this.
'=========
Sub Test()
Dim rCells As Range, rLoopCells As Range
Dim OldAddress As Variant
Dim NewAdress As Variant
'Set variable to needed cells
If Selection.Cells.Count < 1 Then
MsgBox "You must select at least one cell"
Else
Set rCells = Selection
End If
For Each rLoopCells In rCells
OldAddress = rLoopCells.Address
NewAdress = Replace(OldAddress, "A", "D")
MsgBox NewAddress 'for testing
'ActiveSheet.Range(NewAdress).Value = ActiveSheet.Range(OldAddress).Value
Next rLoopCells
End Sub
'=======
All I want to do is substitute the letter D for the letter A in the address
of "OldAddress".
I am using msgbox to show results before I destroy my data but all I get is
a blank msgbox.
What do I have wrong in the above code? (I know the problem lies within the
"Replace" statement).
--
Regards
VBA.Noob.Confused
XP Pro
Office 2007
|