Hi all!
Another day, another problem..
Here is what's going on:
I have an excel where there are two sheets. Sheet 1 contains Phone numbers in Column X in the following format: 050-7080-6030. I need to copy this to Sheet 2 while at the same time removing "-" (I achieved this by creating a table -see the code below-, for various reasons). I simply used recording for the copying part to paste it as a value -which works just fine- however, on Sheet 2 I lose all leading zeros. I have tried applying cell format as text for the whole sheet (both of them) and even vba code like NumberFormat = ... however nothing seems to work.
Here are the codes:
Sub copy2()
'
' copy2 Macro
'
Rows("3:10").Select
Range("D3").Activate
Selection.copy
Sheets("Sheet2").Select
Rows("3:10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
Sub PhoneNumbers()
Dim wks As Worksheet
Dim fndList As Integer
Dim rplcList As Integer
Dim tbl As ListObject
Dim myArray As Variant
Set wks = Sheets("Sheet2")
Set tbl = Worksheets("ALL_DB").ListObjects("Phone")
Set TempArray = tbl.DataBodyRange
myArray = Application.Transpose(TempArray)
fndList = 1
rplcList = 2
With wks
For x = LBound(myArray, 1) To UBound(myArray, 2)
.Range("X3:X10").Replace What:=myArray(fndList, x), Replacement:=myArray(rplcList, x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next x
End With
End Sub
Anyone have any idea how to solve this?
Thank you in advance!
Another day, another problem..
Here is what's going on:
I have an excel where there are two sheets. Sheet 1 contains Phone numbers in Column X in the following format: 050-7080-6030. I need to copy this to Sheet 2 while at the same time removing "-" (I achieved this by creating a table -see the code below-, for various reasons). I simply used recording for the copying part to paste it as a value -which works just fine- however, on Sheet 2 I lose all leading zeros. I have tried applying cell format as text for the whole sheet (both of them) and even vba code like NumberFormat = ... however nothing seems to work.
Here are the codes:
Sub copy2()
'
' copy2 Macro
'
Rows("3:10").Select
Range("D3").Activate
Selection.copy
Sheets("Sheet2").Select
Rows("3:10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
Sub PhoneNumbers()
Dim wks As Worksheet
Dim fndList As Integer
Dim rplcList As Integer
Dim tbl As ListObject
Dim myArray As Variant
Set wks = Sheets("Sheet2")
Set tbl = Worksheets("ALL_DB").ListObjects("Phone")
Set TempArray = tbl.DataBodyRange
myArray = Application.Transpose(TempArray)
fndList = 1
rplcList = 2
With wks
For x = LBound(myArray, 1) To UBound(myArray, 2)
.Range("X3:X10").Replace What:=myArray(fndList, x), Replacement:=myArray(rplcList, x), _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
Next x
End With
End Sub
Anyone have any idea how to solve this?
Thank you in advance!