missbanana
New Member
- Joined
- Nov 25, 2024
- Messages
- 1
- Office Version
- 365
- 2010
- 2007
- Platform
- Windows
Hi all, long time lurker first time poster.
I am somewhat of a VBA newbie and am trying to write a script to assign values from one of my workbooks to a template workbook, however the data in the source file is non contiguous. The below script does not cause an error. however the data from the first column in my source range is copied over to every column in the wb0 range. Wondering if there is an easier way than referencing each column individually? I came across Application.Union but not sure it will work for my situation? Any advice would be most welcome thank you!
Option Explicit
Sub Cavendish_Data()
Application.DisplayAlerts = False
Dim wb0 As Workbook
Dim wb1 As Workbook
Set wb0 = ActiveWorkbook
Set wb1 = Workbooks.Open("C:\HVO\Monthly Dust\Workbook1.xls")
'Assign values from banana daily average outputs to template
LastRow = wb1.Sheets("Block3_1_2").Range("A1").End(xlDown).Row
wb0.Sheets("Daily AVG").Range("H2:H" & LastRow & "," & "I2:I" & LastRow).Value = wb1.Sheets("Block3_1_2").Range("B2:B" & LastRow & "," & "E2:E" & LastRow).Value
I am somewhat of a VBA newbie and am trying to write a script to assign values from one of my workbooks to a template workbook, however the data in the source file is non contiguous. The below script does not cause an error. however the data from the first column in my source range is copied over to every column in the wb0 range. Wondering if there is an easier way than referencing each column individually? I came across Application.Union but not sure it will work for my situation? Any advice would be most welcome thank you!
Option Explicit
Sub Cavendish_Data()
Application.DisplayAlerts = False
Dim wb0 As Workbook
Dim wb1 As Workbook
Set wb0 = ActiveWorkbook
Set wb1 = Workbooks.Open("C:\HVO\Monthly Dust\Workbook1.xls")
'Assign values from banana daily average outputs to template
LastRow = wb1.Sheets("Block3_1_2").Range("A1").End(xlDown).Row
wb0.Sheets("Daily AVG").Range("H2:H" & LastRow & "," & "I2:I" & LastRow).Value = wb1.Sheets("Block3_1_2").Range("B2:B" & LastRow & "," & "E2:E" & LastRow).Value