Darkcloud617
New Member
- Joined
- Sep 7, 2017
- Messages
- 38
Hello all,
I have been working on this code to
1. let user pick file
2. copy all cells that contain data on sheet 1, 2, 3, 4 and over 30
3. paste into first blank row of source workbook on Sheet 4
For some reason this seems to only paste one cell into "A" on sheet 4 on the first blank row of source workbook. I cant figure out how to make it copy all data (cells that contain data) from user defined workbook (wb2, with multiple sheets) and paste into source workbook (wb1) on sheet 4 on first blank row. Any help is greatly appreciated.
I have been working on this code to
1. let user pick file
2. copy all cells that contain data on sheet 1, 2, 3, 4 and over 30
3. paste into first blank row of source workbook on Sheet 4
For some reason this seems to only paste one cell into "A" on sheet 4 on the first blank row of source workbook. I cant figure out how to make it copy all data (cells that contain data) from user defined workbook (wb2, with multiple sheets) and paste into source workbook (wb1) on sheet 4 on first blank row. Any help is greatly appreciated.
Code:
Sub Notes1()
'Last row in column
Dim WS As Worksheet
Dim LastCell As Range
Dim LastCellRowNumber As Long
Set WS = Worksheets("Sheet 4")
With WS
Set LastCell = .Cells(.Rows.Count, "C").End(xlUp)
LastCellRowNumber = LastCell.Row + 1
End With
Dim wb As Workbook, wb2 As Workbook
Dim vFile As Variant
'Set source workbook
Set wb = ActiveWorkbook
'Open the target workbook
vFile = Application.GetOpenFilename("Excel-files,*.xlsx", _
1, "Select File To Open", , False)
'if the user didn't select a file, exit sub
If TypeName(vFile) = "Boolean" Then Exit Sub
Workbooks.Open vFile
'Set selectedworkbook
Set wb2 = ActiveWorkbook
'Go to selected workbook
wb2.Activate
'Select cells to copy
Sheets("Week 1").Activate
wb2.Worksheets("Week 1").Rows.End(xlUp).Offset(1, 0).Select
Selection.Copy
'Go back to original workbook
wb.Activate
'Paste Row starting at the last empty row
wb.Worksheets("Sheet 4").Range("C" & LastCellRowNumber).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Application.ScreenUpdating = True
'repeats
wb2.Activate
Sheets("Week 2").Activate
wb2.Worksheets("Week 2").Rows.End(xlUp).Offset(1, 0).Select
Selection.Copy
wb.Activate
wb.Worksheets("Sheet 4").Range("A" & LastCellRowNumber).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Application.ScreenUpdating = True
wb2.Activate
Sheets("Week 3").Activate
wb2.Worksheets("Week 3").Rows.End(xlUp).Offset(1, 0).Select
Selection.Copy
wb.Activate
wb.Worksheets("Sheet 4").Range("A" & LastCellRowNumber).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Application.ScreenUpdating = True
wb2.Activate
Sheets("Week 4").Activate
wb2.Worksheets("Week 4").Rows.End(xlUp).Offset(1, 0).Select
Selection.Copy
wb.Activate
wb.Worksheets("Sheet 4").Range("A" & LastCellRowNumber).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Application.ScreenUpdating = True
wb2.Activate
Sheets("Over 30").Activate
wb2.Worksheets("Over 30").Rows.End(xlUp).Offset(1, 0).Select
Selection.Copy
wb.Activate
wb.Worksheets("Sheet 4").Range("A" & LastCellRowNumber).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Application.ScreenUpdating = True
'Close
wb2.Close
End Sub