This is the code I am using:
Sub Extract
' Extract the Contract Account Numbers and delete Column A
FinalRow = Range("A" & Rows.Count).End(xlUp).Row
Columns("B:B").Select
Selection.Insert Shift:=xlToRight
Range("A1").Select
Selection.Copy
Range("B1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("B2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-1],11)"
Range("B2").Select
Range("B2").AutoFill Destination:=Range("B2:B" & Cells(Rows.Count, "A").End(xlUp).Row)
Columns("B:B").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("A:A").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("A1").Select
End sub
It extracts the 11 rightmost characters from Column A, then use cell B2 to copy the formula down. Only then does it replace the formulas with the values. The code works perfect if is run alone, but when I paste it into a larger block of code, it copies the absolute values down, so the VALUE in B2 is copied down and not the FORMULA.
Are there factors in VBA that causes this? Or is there a way that I can ensure that the formulas are copied down
Sub Extract
' Extract the Contract Account Numbers and delete Column A
FinalRow = Range("A" & Rows.Count).End(xlUp).Row
Columns("B:B").Select
Selection.Insert Shift:=xlToRight
Range("A1").Select
Selection.Copy
Range("B1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("B2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-1],11)"
Range("B2").Select
Range("B2").AutoFill Destination:=Range("B2:B" & Cells(Rows.Count, "A").End(xlUp).Row)
Columns("B:B").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("A:A").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlToLeft
Range("A1").Select
End sub
It extracts the 11 rightmost characters from Column A, then use cell B2 to copy the formula down. Only then does it replace the formulas with the values. The code works perfect if is run alone, but when I paste it into a larger block of code, it copies the absolute values down, so the VALUE in B2 is copied down and not the FORMULA.
REQUIRED |
Cont. Acct |
21004149973 |
21004149973 |
21004149965 |
21004149965 |
21004149965 |
21004149957 |
OUTPUT |
Cont. Acct |
21004149973 |
21004149973 |
21004149973 |
21004149973 |
21004149973 |
21004149973 |
Are there factors in VBA that causes this? Or is there a way that I can ensure that the formulas are copied down