Hi,
I have this code that helps to insert a column in various tables (copies and then paste special the data)
Is there a way to adjust this code to delete the previous column? in stead off inserting the column - bare in mind the last column has formulas, i would like the column before this to be deleted
Thanks
I have this code that helps to insert a column in various tables (copies and then paste special the data)
Is there a way to adjust this code to delete the previous column? in stead off inserting the column - bare in mind the last column has formulas, i would like the column before this to be deleted
VBA Code:
Sub Insert_Col()
Dim ws As Worksheet
Dim lr As Long
Dim lc As Long
Dim myrng As Range
Dim myvar As Variant
Application.ScreenUpdating = False
On Error GoTo Oops:
'assuming there are are no sheets that need to be ignored ???
For Each ws In ThisWorkbook.Sheets
Select Case ws.Name
Case "Main Menu", "Notes", "Contents", "Table 8", "Table 10_SOC10", "Table 10_SOC00", "Table 7_SIC03", "Table 11", "Table 13", "Table 14" ' Sheets to be ignored
GoTo Ignore:
Case Else 'Otherwise do insert
With ws
'last column by interrogating row 3!!!!!!!!!!
lc = .Cells(3, Columns.Count).End(xlToLeft).Column
'last row
lr = .Cells(Rows.Count, lc).End(xlUp).Row
'range of interest
Set myrng = .Range(.Cells(1, lc), .Cells(lr, lc))
'Assign range values to array myvar
myvar = myrng.Value
'insert a new column
myrng.Columns(1).EntireColumn.Insert
' range values to new column
myrng.Offset(0, -1).Value = myvar
'Copy format to new column
myrng.Copy
myrng.Offset(0, -1).PasteSpecial xlPasteFormats
Application.CutCopyMode = False
myrng.Offset(0, -1).ColumnWidth = myrng.ColumnWidth
End With
Thanks