Hello Experts,
I am using the below VBA to open an excel workbook in a separate excel file elsewhere and copy paste 2 columns. It works fine however I am trying to clear the formatting as has merged cells and ends up transfering all columns in that merged range.
Would anyone know which addition to insert into my VBA to clear the formatting before copying and pasting the columns? So the copy paste would be work. I have tried a few attempts with no success.
Sub Jan_credits()
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'*****************set variables
Dim ws As Worksheet
Dim wkbk
Dim wkbk2
Set wkbk = ActiveWorkbook
'*****************Extraction
fname = Application.GetOpenFilename
If fname <> False Then
Workbooks.Open Filename:=fname
Else: Exit Sub
End If
Set wkbk2 = ActiveWorkbook
'*****************Copy and paste
ActiveWindow.WindowState = xlMaximized
Range("d2:d500").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
wkbk.Activate
Range("ba3012").Select
Selection.PasteSpecial Paste:=xlValues
wkbk2.Activate
Range("f2:f500").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
wkbk.Activate
Range("bb3012").Select
Selection.PasteSpecial Paste:=xlValues
wkbk2.Activate
wkbk2.Close
wkbk.Activate
End Sub
Thanks!
John
I am using the below VBA to open an excel workbook in a separate excel file elsewhere and copy paste 2 columns. It works fine however I am trying to clear the formatting as has merged cells and ends up transfering all columns in that merged range.
Would anyone know which addition to insert into my VBA to clear the formatting before copying and pasting the columns? So the copy paste would be work. I have tried a few attempts with no success.
Sub Jan_credits()
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'*****************set variables
Dim ws As Worksheet
Dim wkbk
Dim wkbk2
Set wkbk = ActiveWorkbook
'*****************Extraction
fname = Application.GetOpenFilename
If fname <> False Then
Workbooks.Open Filename:=fname
Else: Exit Sub
End If
Set wkbk2 = ActiveWorkbook
'*****************Copy and paste
ActiveWindow.WindowState = xlMaximized
Range("d2:d500").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
wkbk.Activate
Range("ba3012").Select
Selection.PasteSpecial Paste:=xlValues
wkbk2.Activate
Range("f2:f500").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
wkbk.Activate
Range("bb3012").Select
Selection.PasteSpecial Paste:=xlValues
wkbk2.Activate
wkbk2.Close
wkbk.Activate
End Sub
Thanks!
John