kbenjamin827
New member
- Joined
- Jul 5, 2018
- Messages
- 2
- Reaction score
- 0
- Points
- 0
- Excel Version(s)
- 2007
Hi all,
I need a macro that opens a file, then copy and pastes everything under a specific column (named Total) and place those values under the Total column in the workbook. What I have so far is a macro that opens a file, and copies and pastes values from a fixed cell range, into a fixed destination.
Any suggestions?
I need a macro that opens a file, then copy and pastes everything under a specific column (named Total) and place those values under the Total column in the workbook. What I have so far is a macro that opens a file, and copies and pastes values from a fixed cell range, into a fixed destination.
Code:
Sub Foo()
Dim vFile As Variant
Dim wbCopyTo As Workbook
Dim wsCopyTo As Worksheet
Dim wbCopyFrom As Workbook
Dim wsCopyFrom As Worksheet
Set wbCopyTo = ActiveWorkbook
Set wsCopyTo = ActiveSheet
'-------------------------------------------------------------
'Open file with data to be copied
vFile = Application.GetOpenFilename("Excel Files (*.xl*)," & _
"*.xl*", 1, "Select Excel File", "Open", False)
'If Cancel then Exit
If TypeName(vFile) = "Boolean" Then
Exit Sub
Else
Set wbCopyFrom = Workbooks.Open(vFile)
Set wsCopyFrom = wbCopyFrom.Worksheets(1)
End If
'--------------------------------------------------------------
'Copy Range
wsCopyFrom.Range("D6:R26").Copy
wsCopyTo.Range("D7").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
wsCopyFrom.Range("S6:S26").Copy
wsCopyTo.Range("X7").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'Close file that was opened
wbCopyFrom.Close SaveChanges:=False
End Sub
Any suggestions?