I have two workbooks (source and target) and I want to copy column A in the source workbook to column A in the target workbook. I used this code for the above.
Sub CopyColumnToWorkbook()
Dim sourceColumn As Range, targetColumn As Range
Set sourceColumn = Workbooks("Source").Worksheets("Sheet1").Columns("A")
Set targetColumn = Workbooks("Target").Worksheets("Sheet1").Columns("A")
sourceColumn.Copy Destination:=targetColumn
End Sub
But the source sheet contains cells with formulas. I just want to copy the cell values, but not formulas.
What changes should I make to the above code?
Sub BOM()
Dim sourceColumn As Range, targetColumn As Range
Set sourceColumn = Workbooks("MASTER").Worksheets("Sheet1").Columns("C")
Set targetColumn = Workbooks("BOM").Worksheets("Sheet1").Columns("A")
sourceColumn.Copy Destination:=targetColumn
Set sourceColumn = Workbooks("MASTER").Worksheets("Sheet1").Columns("D")
Set targetColumn = Workbooks("BOM").Worksheets("Sheet1").Columns("B")
sourceColumn.Copy Destination:=targetColumn
Set sourceColumn = Workbooks("MASTER").Worksheets("Sheet1").Columns("E")
Set targetColumn = Workbooks("BOM").Worksheets("Sheet1").Columns("C")
sourceColumn.Copy Destination:=targetColumn
End Sub
This is the code I used to copy the cells from one workbook to another. It's working fine on my PC which is running Windows 7 Excel 2010, but I want to run the same code on PCs which are using XP Excel 2007.
I am getting Runtime error: Subscript out of range.
while running the macro, and when I click debug button, it points to the third line of code.