picklefactory
Well-known Member
- Joined
- Jan 28, 2005
- Messages
- 508
- Office Version
- 365
- Platform
- Windows
Hi folks
I'm struggling again..... no change there.
I'm collecting data in one wb and need to copy/paste but also split it to a 2nd wb. Below is my source data in wba. I want the first range, range 1, being all rows to the first blank row, to paste to cols A1:D1 in wbb and the range of source data below the first blank row, range 2, to paste to cols F1:H1 in wbb. Both ranges of data can vary in length, so needs to be dynamic finding both to and from the first blank row.
So what I'm trying to achieve is this
I found and jiggled some code which will copy/paste the first range OK, but can't fathom how to find/copy the 2nd range, range 2, to cols F1:H1 in wbb?
This is what I have so far for the first range, which works OK
If someone could maybe gimme a hint please on how to grab the 2nd range it would be much appreciated?
Thanks
I'm struggling again..... no change there.
I'm collecting data in one wb and need to copy/paste but also split it to a 2nd wb. Below is my source data in wba. I want the first range, range 1, being all rows to the first blank row, to paste to cols A1:D1 in wbb and the range of source data below the first blank row, range 2, to paste to cols F1:H1 in wbb. Both ranges of data can vary in length, so needs to be dynamic finding both to and from the first blank row.
WorkbookA.xlsx | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | RANGE 1 | RANGE 1 | RANGE 1 | RANGE 1 | ||
2 | RANGE 1 | RANGE 1 | RANGE 1 | RANGE 1 | ||
3 | RANGE 1 | RANGE 1 | RANGE 1 | RANGE 1 | ||
4 | ||||||
5 | RANGE 2 | RANGE 2 | RANGE 2 | |||
6 | RANGE 2 | RANGE 2 | RANGE 2 | |||
7 | RANGE 2 | RANGE 2 | RANGE 2 | |||
8 | RANGE 2 | RANGE 2 | RANGE 2 | |||
9 | RANGE 2 | RANGE 2 | RANGE 2 | |||
10 | RANGE 2 | RANGE 2 | RANGE 2 | |||
11 | RANGE 2 | RANGE 2 | RANGE 2 | |||
12 | RANGE 2 | RANGE 2 | RANGE 2 | |||
13 | RANGE 2 | RANGE 2 | RANGE 2 | |||
14 | RANGE 2 | RANGE 2 | RANGE 2 | |||
15 | RANGE 2 | RANGE 2 | RANGE 2 | |||
Sheet3 |
So what I'm trying to achieve is this
WorkbookB.xlsm | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | |||
1 | RANGE 1 | RANGE 1 | RANGE 1 | RANGE 1 | RANGE 2 | RANGE 2 | RANGE 2 | |||
2 | RANGE 1 | RANGE 1 | RANGE 1 | RANGE 1 | RANGE 2 | RANGE 2 | RANGE 2 | |||
3 | RANGE 1 | RANGE 1 | RANGE 1 | RANGE 1 | RANGE 2 | RANGE 2 | RANGE 2 | |||
4 | RANGE 2 | RANGE 2 | RANGE 2 | |||||||
5 | RANGE 2 | RANGE 2 | RANGE 2 | |||||||
6 | RANGE 2 | RANGE 2 | RANGE 2 | |||||||
7 | RANGE 2 | RANGE 2 | RANGE 2 | |||||||
8 | RANGE 2 | RANGE 2 | RANGE 2 | |||||||
9 | RANGE 2 | RANGE 2 | RANGE 2 | |||||||
10 | RANGE 2 | RANGE 2 | RANGE 2 | |||||||
11 | RANGE 2 | RANGE 2 | RANGE 2 | |||||||
Sheet3 |
I found and jiggled some code which will copy/paste the first range OK, but can't fathom how to find/copy the 2nd range, range 2, to cols F1:H1 in wbb?
This is what I have so far for the first range, which works OK
If someone could maybe gimme a hint please on how to grab the 2nd range it would be much appreciated?
Thanks
VBA Code:
Sub COPYRANGE()
Dim wba As Workbook
Dim wbb As Workbook
Set wba = Workbooks("Workbook A.xlsx")
Set wbb = Workbooks("Workbook B.xlsm")
With wba.Worksheets("Sheet1")
.Range("A1:D1", .Range("A1:D1").End(xlDown)).Copy
End With
wbb.Worksheets("Sheet2").Range("A1:D1").PasteSpecial xlPasteValues
End Sub