Hello All,
I need to copy data from one workbook to another. The catch is the source workbook has a name that will always change. The second is a static workbook.
I have a macro that uses msgboxes to prompt the user for the correct template file accomplish this goal quite well however it is confusing my enduser ( who is not very computer savy).
So I figure it is easy enough to identify the static file I can either hardcode the name or use ThisWorkbook, or even Active.Workbook with work.
But what is stumping me is adressing the "Other"Workbook. I cant always be sure its will be indexed as Workbooks(1) or 2.
My user cant reliably open them in the Correct Order.
Why Wouldn't this work?
Below is the Macro I have come up with with the help of Caleeco.
The Original Thread is here: http://www.mrexcel.com/forum/excel-...ng-between-two-excel-sheets-out-setnames.html
Thanks in advance!
Joseph.
I need to copy data from one workbook to another. The catch is the source workbook has a name that will always change. The second is a static workbook.
I have a macro that uses msgboxes to prompt the user for the correct template file accomplish this goal quite well however it is confusing my enduser ( who is not very computer savy).
So I figure it is easy enough to identify the static file I can either hardcode the name or use ThisWorkbook, or even Active.Workbook with work.
But what is stumping me is adressing the "Other"Workbook. I cant always be sure its will be indexed as Workbooks(1) or 2.
My user cant reliably open them in the Correct Order.
Why Wouldn't this work?
Code:
If ThisWorkbook = Workbooks(1) Then
Set wb1 = Workbooks(2)
Set wb2 = Workbooks(1)
Else
Set wb1 = Workbooks(1)
Set wb2 = ThisWorkbook
End If
Below is the Macro I have come up with with the help of Caleeco.
The Original Thread is here: http://www.mrexcel.com/forum/excel-...ng-between-two-excel-sheets-out-setnames.html
Code:
Sub Import_Customer_Information()
Dim wb1 As Workbook, wb2 As Workbook
Dim answer As Integer
If Workbooks.Count > 2 Then
MsgBox "You may only have 2 Workbooks Open when running this Macro. Exiting...", vbCritical, "Warning"
Exit Sub
End If
If Workbooks.Count < 2 Then
MsgBox "You need to have both your customer info sheet and templete file open! Exiting...", vbCritical, "Warning"
Exit Sub
End If
answer = MsgBox("Is the following Workbook your Template File? " & Workbooks(1).Name, vbYesNo + vbQuestion, "Primary Workbook")
If answer = vbYes Then
Set wb2 = ThisWorkbook
Set wb1 = Workbooks(1)
Else
MsgBox "Okay, using " & Workbooks(2).Name & " as the Template File.", vbOKOnly + vbInformation, "Primary Workbook"
Set wb1 = Workbooks(1)
Set wb2 = Workbooks(2)
End If
wb1.Activate
Range("A2").Select
Selection.Copy
wb2.Activate
Range("G8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("K2").Select
Selection.Copy
wb2.Activate
Range("D9,J3,B13").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("AC2").Select
Selection.Copy
wb2.Activate
Range("J6").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("Q2").Select
Selection.Copy
wb2.Activate
Range("G10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("R2").Select
Selection.Copy
wb2.Activate
Range("G11").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("T2").Select
Selection.Copy
wb2.Activate
Range("J10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("S2").Select
Selection.Copy
wb2.Activate
Range("J11").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("L2").Select
Selection.Copy
wb2.Activate
Range("B14").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("M2").Select
Selection.Copy
wb2.Activate
Range("B15").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("N2").Select
Selection.Copy
wb2.Activate
Range("B16").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("O2").Select
Selection.Copy
wb2.Activate
Range("D16").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("P2").Select
Selection.Copy
wb2.Activate
Range("G16").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("U2").Select
Selection.Copy
wb2.Activate
Range("J13").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("V2").Select
Selection.Copy
wb2.Activate
Range("J14").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("W2").Select
Selection.Copy
wb2.Activate
Range("J15").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("X2").Select
Selection.Copy
wb2.Activate
Range("J16").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("Y2").Select
Selection.Copy
wb2.Activate
Range("J17").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("Z2").Select
Selection.Copy
wb2.Activate
Range("K17").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("AA2").Select
Selection.Copy
wb2.Activate
Range("M17").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("B2:B82").Select
Selection.Copy
wb2.Activate
Range("B22:B102").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("F2:F82").Select
Selection.Copy
wb2.Activate
Range("D22:D102").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("G2:G82").Select
Selection.Copy
wb2.Activate
Range("G22:G102").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("D2:D82").Select
Selection.Copy
wb2.Activate
Range("H22:H102").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("E2:E82").Select
Selection.Copy
wb2.Activate
Range("J22:J102").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("I2:I82").Select
Selection.Copy
wb2.Activate
Range("K22:K102").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
wb1.Activate
Range("H2:H82").Select
Selection.Copy
wb2.Activate
Range("M22:M102").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Dim rng As Range
Set rng = Range("B22:B102").SpecialCells(xlCellTypeBlanks)
rng.EntireRow.Delete
Range("B22:B102").EntireRow.Hidden = False
End Sub
Thanks in advance!
Joseph.