keiranwyllie
New Member
- Joined
- May 12, 2017
- Messages
- 47
Good evening,
Can someone help me with the following please?
I have a workbook with a number of worksheets that are filled from a userform.
I'd like to be able to copy the filled cells from several worksheets into one (same workbook).
Sheet1 is filled from columns B:O (from row 9 and down).
Sheet2 is filled using the same as above.
I need the data from sheet1 copied first, then sheet2 copied from the first blank row below sheet1s copied data.
Below is some test code but I can't work out why it's only copying column B of both sheets, and not C through O.
If anyone can shed some light, that'd be awesome.
Can someone help me with the following please?
I have a workbook with a number of worksheets that are filled from a userform.
I'd like to be able to copy the filled cells from several worksheets into one (same workbook).
Sheet1 is filled from columns B:O (from row 9 and down).
Sheet2 is filled using the same as above.
I need the data from sheet1 copied first, then sheet2 copied from the first blank row below sheet1s copied data.
Below is some test code but I can't work out why it's only copying column B of both sheets, and not C through O.
Code:
Sub test()
Application.ScreenUpdating = False
Dim s1 As Excel.Worksheet
Dim s2 As Excel.Worksheet
Dim iLastCellS2 As Excel.Range
Dim iLastRowS1 As Long
Set s1 = Sheets("Data")
Set s2 = Sheets("Data2")
Set s3 = Sheets("All")
s3.Range("A1:AI5000").Clear
' get last row of J in Sheet1
iLastRowS1 = s1.Cells(s1.Rows.Count, "B").End(xlUp).Row
' get last AVAILABLE cell to past into
Set iLastCellS3 = s3.Cells(s3.Rows.Count, "A").End(xlUp).Offset(1, 0)
'copy into sheet2
s1.Range("B9", s1.Cells(iLastRowS1, "B")).Copy iLastCellS3
' get last row of K and sheet2
iLastRowS2 = s2.Cells(s2.Rows.Count, "B").End(xlUp).Row
' get last AVAILABLE cell to past into
Set iLastCellS3 = s3.Cells(s3.Rows.Count, "A").End(xlUp).Offset(1, 0)
'copy into sheet2
s2.Range("B9", s2.Cells(iLastRowS2, "B")).Copy iLastCellS3
End Sub
If anyone can shed some light, that'd be awesome.