J
Jeff Granger
Please excuse my ignorance.
I'm trying to use the following macro to remove carriage returns ( and other
characters) from a list of addresses.
Carriage Return & Line Feed Clean-up Macro
Option Explicit
Sub cleanEmUp()
Dim myBadChars As Variant
Dim myGoodChars As Variant
Dim iCtr As Long
myBadChars = Array(Chr(10), Chr(13)) '<--What showed up in CellView?
myGoodChars = Array("","|") '<--the new characters?
If UBound(myGoodChars) <> UBound(myBadChars) Then
MsgBox "Design error!"
Exit Sub
End If
For iCtr = LBound(myBadChars) To UBound(myBadChars)
ActiveSheet.Cells.Replace What:=myBadChars(iCtr), _
Replacement:=myGoodChars(iCtr), _
LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False
Next iCtr
End Sub
The problem is that when I try and edit the macro to put specific cell
references instead of "Array" and run the macro I get a VB Compile Error and
Syntax error.
eg.
Option Explicit
Sub cleanEmUp()
Dim myBadChars As Variant
Dim myGoodChars As Variant
Dim iCtr As Long
" myBadChars = A3:A20(Chr(10), Chr(13)) '<--What showed up in CellView?"
" myGoodChars = B3:B20("""",""|"") '<--the new characters?"
If UBound(myGoodChars) <> UBound(myBadChars) Then
" MsgBox ""Design error!"""
Exit Sub
End If
For iCtr = LBound(myBadChars) To UBound(myBadChars)
" ActiveSheet.Cells.Replace What:=myBadChars(iCtr), _"
" Replacement:=myGoodChars(iCtr), _"
" LookAt:=xlPart, SearchOrder:=xlByRows, _"
MatchCase:=False
Next iCtr
End Sub
Can anyone tell me what I'm doing wrong?
Jeff
I'm trying to use the following macro to remove carriage returns ( and other
characters) from a list of addresses.
Carriage Return & Line Feed Clean-up Macro
Option Explicit
Sub cleanEmUp()
Dim myBadChars As Variant
Dim myGoodChars As Variant
Dim iCtr As Long
myBadChars = Array(Chr(10), Chr(13)) '<--What showed up in CellView?
myGoodChars = Array("","|") '<--the new characters?
If UBound(myGoodChars) <> UBound(myBadChars) Then
MsgBox "Design error!"
Exit Sub
End If
For iCtr = LBound(myBadChars) To UBound(myBadChars)
ActiveSheet.Cells.Replace What:=myBadChars(iCtr), _
Replacement:=myGoodChars(iCtr), _
LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False
Next iCtr
End Sub
The problem is that when I try and edit the macro to put specific cell
references instead of "Array" and run the macro I get a VB Compile Error and
Syntax error.
eg.
Option Explicit
Sub cleanEmUp()
Dim myBadChars As Variant
Dim myGoodChars As Variant
Dim iCtr As Long
" myBadChars = A3:A20(Chr(10), Chr(13)) '<--What showed up in CellView?"
" myGoodChars = B3:B20("""",""|"") '<--the new characters?"
If UBound(myGoodChars) <> UBound(myBadChars) Then
" MsgBox ""Design error!"""
Exit Sub
End If
For iCtr = LBound(myBadChars) To UBound(myBadChars)
" ActiveSheet.Cells.Replace What:=myBadChars(iCtr), _"
" Replacement:=myGoodChars(iCtr), _"
" LookAt:=xlPart, SearchOrder:=xlByRows, _"
MatchCase:=False
Next iCtr
End Sub
Can anyone tell me what I'm doing wrong?
Jeff