Hi..I am pretty new to VBA. I am trying to achieve the following but not able to proceed further:
Environment: Excel 2010
I have a source file (a.xls)
Allow the user to open a file (b.xls)
Copy 3 non-consecutive columns from b.xls to a.xls
Source columns could include blank cells too
This is my current code (sourced from internet + by recording a macro):
Opening a file: (It works !)
Sub CopyTP2DVP()
NewFN = Application.GetOpenFilename(FileFilter:="All Excel Files (*.xlsx), *.xlsx", Title:="Please select a file")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
Workbooks.Open Filename:=NewFN
End If
End Sub
For Copy: (It doesn't work ! As you can see, the file names are hard coded but, in my case, different users will use the macro. So, file names will be different. So, I want to have this flexibility)
Sub Macro2()
'
' Macro2 Macro
'
'
Windows("TP_Result_Anlys Rprt_Tplt.xlsx").Activate
Range("A37").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows("qr10021.xlsm").Activate
Range("C8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("D8").Select
Windows("TP_Result_Anlys Rprt_Tplt.xlsx").Activate
Range("C37").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Windows("qr10021.xlsm").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("TP_Result_Anlys Rprt_Tplt.xlsx").Activate
Range("F37").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Windows("qr10021.xlsm").Activate
Range("N8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("M8").Select
End Sub
Bookmarks