Hello i am trying to figure out how to paste a range of cells on to the next row when there are a few blanks in the row above. My code keeps overwriting them.
Here is my code:
For example, for the sheet pear the majority of the time the range B2:B5 is empty but if there is a value instead of going on the correct row matching its refe it goes to the top row at the beginning of the spreadsheet since are all the rows above are blank.
Here is my code:
Code:
Sub GetSheetstest()
Dim Path As String
Dim FileName As String
Dim Sheet As Worksheet
Dim pasteRow As Integer
pasteRow = 2
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Windows("Summary Data v4.xlsm").Activate
With Sheets("Sheet1")
.Rows(2 & ":" & .Rows.Count).Delete
End With
Path = "C:\blahz"
FileName = Dir(Path & "*.xlsm")
Do While FileName <> ""
Workbooks.Open FileName:=Path & FileName, ReadOnly:=True
Sheets("Case Summary").Range("B2:B46").Copy
Windows("Summary Data v4.xlsm").Activate
Range("A" & pasteRow).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Workbooks(FileName).Activate
Sheets("pear").Range("B2:B5").Copy
Windows("Summary Data v4.xlsm").Activate
Range("AT" & pasteRow).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Workbooks(FileName).Activate
Sheets(" apple").Range("B2:B18").Copy
Windows("Summary Data v4.xlsm").Activate
Range("AX" & pasteRow).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Workbooks(FileName).Activate
Sheets("orange").Range("B2:B22").Copy
Windows(" Summary data v4.xlsm").Activate
Range("BO" & pasteRow).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
pasteRow = pasteRow + 1
Workbooks(FileName).Close
FileName = Dir()
Loop
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
Last edited by a moderator: