nirvehex
12-30-2014, 11:04 AM
Hello,
I'm trying to use VBA to copy Table2 from Sheet1 to Sheet2. The only problem is each time I do this, the table is named differently so my VBA code breaks down.
'Copies Table2 to Sheet2
Sheets("Sheet1").Select
Range("Table2[#All]").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A2").Select
ActiveSheet.Paste
'Inserts Column and Inserts Calculation
Columns("C:C").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("Table22[[#Headers],[Column1]]").Select
ActiveCell.FormulaR1C1 = "Calculation"
Range("C3").Select
ActiveCell.FormulaR1C1 = "=5*5/.48"
Range("C4").Select
The first time it pasted the table as Table22 which I was I named it such in my code. However, after I deleted it and ran it again it named it Table27. And if I delete it and repaste it again, it's called something else. How do I adjust the code to either name it the same thing every time or account for a variable name change?
Thanks!
I'm trying to use VBA to copy Table2 from Sheet1 to Sheet2. The only problem is each time I do this, the table is named differently so my VBA code breaks down.
'Copies Table2 to Sheet2
Sheets("Sheet1").Select
Range("Table2[#All]").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A2").Select
ActiveSheet.Paste
'Inserts Column and Inserts Calculation
Columns("C:C").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("Table22[[#Headers],[Column1]]").Select
ActiveCell.FormulaR1C1 = "Calculation"
Range("C3").Select
ActiveCell.FormulaR1C1 = "=5*5/.48"
Range("C4").Select
The first time it pasted the table as Table22 which I was I named it such in my code. However, after I deleted it and ran it again it named it Table27. And if I delete it and repaste it again, it's called something else. How do I adjust the code to either name it the same thing every time or account for a variable name change?
Thanks!