I'm a newbie to VBA and I need help trying to populate a Master Workbook from a Client Template Workbook that i fill out.
So my idea is to transfer the data, by the press of a button, from two worksheets located in the Client Template document and populate "Sheet1" in the Master Workbook.
Due to my lack of knowledge in VBA I got to the point where I can populate "Sheet1" of the Master Workbook but I trapped myself where I can´t use my VBA code to populate the next row of the Master document with a new client information.
At the end I would like the Master Workbook to have a list of all my clients information; and if at all possible, if I revisit a Client's information and transfer its data to the Master Workbook, I would like for it to overwrite the current information, using the Client's Name as the reference.
I'm pretty sure there is a better way to do this but here is my code:
Sub copy_paste_non_adjacent_cells()
Dim SourceSht As Worksheet
Dim SourceSht2 As Worksheet
Dim TargetSht As Worksheet
Dim mydata As Workbook
Dim pasteRange As Range
Dim SourceRng As Variant
Dim SourceRng2 As Variant
Dim TargetRng As Variant
Dim TargetRng2 As Variant
Dim r As Long
Dim i As Long
Set SourceSht = ActiveSheet 'ActiveSheet is the Client Template Document
Set mydata = Workbooks.Open("D:\Users\DMol\Desktop\ImportTest.xlsx") 'This is the path to my Master Workbook
Set TargetSht = mydata.Worksheets("Sheet1") 'Master Workbook Sheet 1
SourceRng = Array("B2", "B5", "B6", "B7", "B15", "B17", "B18", "B19", "B36", "B41", "B42", "B44", "B45")
TargetRng = Array("A2", "B2", "C2", "D2", "E2", "F2", "G2", "H2", "I2", "J2", "K2", "L2", "M2")
For i = LBound(SourceRng) To UBound(SourceRng)
TargetSht.Range(TargetRng(i)) = SourceSht.Range(SourceRng(i))
Next i
ThisWorkbook.Activate 'Go back to Client Template WorkBook
Set SourceSht2 = Worksheets("Sheet1") 'Look into Client Template "Sheet1"
SourceRng2 = Array("L14", "L16", "K11", "L11", "M11", "N11", "O11", "P11", "Q11")
TargetRng2 = Array("N2", "O2", "P2", "Q2", "R2", "S2", "T2", "U2", "V2")
For i = LBound(SourceRng2) To UBound(SourceRng2)
TargetSht.Range(TargetRng2(i)) = SourceSht2.Range(SourceRng2(i))
Next i
End Sub
I have attached the two documents for reference. Thank you in advance
Bookmarks