Home |
Search |
Today's Posts |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I had "assumed" some arguments were optional.
-- Regards VBA.Noob.Confused XP Pro Office 2007 "Rick Rothstein (MVP - VB)" wrote: Rick S is using the VBA Replace function which is a lot different than the the REPLACE function from the spreadsheet side of things. VBA's Replace function has 6 arguments, the last 3 of which are Optional. Arg1: expression - Required. String expression containing substring to replace. Arg2: find - Required. Substring being searched for. Arg3: replace - Required. Replacement substring. Arg4: start - Optional. Position within expression where substring search is to begin. If omitted, 1 is assumed. Arg5: count - Optional. Number of substring substitutions to perform. If omitted, the default value is €“1, which means make all possible substitutions. Arg6: compare - Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values. Rick "JLGWhiz" wrote in message ... 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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Address must be 18 characters long | Excel Worksheet Functions | |||
How to create a range address with ADDRESS function? | Excel Worksheet Functions | |||
Address can not be more than 30 characters | Excel Worksheet Functions | |||
replace unicode characters | Excel Programming | |||
Replace non printable characters | Excel Worksheet Functions |