Hey guys,
I'm trying to set up a loop to do through a range of cells and copy them to another sheet in my workbook. I need this loop to stop after 2 consecutive blank cells, that way it doesn't go through all 65536 rows of excel. here's what I've got so far. It goes cell by cell, but theres got to be an easier way to do this. Any help would be greatly appreciated! Thanks!!
I'm trying to set up a loop to do through a range of cells and copy them to another sheet in my workbook. I need this loop to stop after 2 consecutive blank cells, that way it doesn't go through all 65536 rows of excel. here's what I've got so far. It goes cell by cell, but theres got to be an easier way to do this. Any help would be greatly appreciated! Thanks!!
Code:
Public Sub SaveRE()
On Error GoTo prcdErr
Dim strPathSeg As String, strFileSeg As String
Dim r1 As Double, c As Double, i As Double
Dim r2 As Double
r2 = 2
r1 = 10
For c = 10 To 65536
Sheets("DataEntry").Select
If Range("D" & r1) <> "" Then
Range("D" & r1).Select
Selection.Copy
Sheets("Output").Select
Range("A" & r2).Select
ActiveSheet.Paste
Else
i = i + 1
Sheets("DataEntry").Select
If Range("E" & r1) <> "" Then
Range("E" & r1).Select
Selection.Copy
Sheets("Output").Select
Range("B" & r2).Select
ActiveSheet.Paste
Else
i = i + 1
Sheets("DataEntry").Select
If Range("F" & r1) <> "" Then
Range("F" & r1).Select
Selection.Copy
Sheets("Output").Select
Range("C" & r2).Select
ActiveSheet.Paste
Else
i = i + 1
Sheets("DataEntry").Select
If Range("G" & r1) <> "" Then
Range("G" & r1).Select
Selection.Copy
Sheets("Output").Select
Range("D" & r2).Select
ActiveSheet.Paste
Else
i = i + 1
Sheets("DataEntry").Select
If Range("H" & r1) <> "" Then
Range("H" & r1).Select
Selection.Copy
Sheets("Output").Select
Range("E" & r2).Select
ActiveSheet.Paste
Else
i = i + 1
Sheets("DataEntry").Select
If Range("I" & r1) <> "" Then
Range("I" & r1).Select
Selection.Copy
Sheets("Output").Select
Range("F" & r2).Select
ActiveSheet.Paste
Else
i = i + 1
Sheets("DataEntry").Select
If Range("J" & r1) <> "" Then
Range("J" & r1).Select
Selection.Copy
Sheets("Output").Select
Range("G" & r2).Select
ActiveSheet.Paste
Else
i = i + 1
Sheets("DataEntry").Select
If Range("K" & r1) <> "" Then
Range("K" & r1).Select
Selection.Copy
Sheets("Output").Select
Range("H" & r2).Select
ActiveSheet.Paste
Else
i = i + 1
Rows("2:2").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown
r1 = r1 + 1
i = i + 1 'Null Column Counter
If i > 2 Then 'More than 2 Null columns
Exit For 'No more data to import in this row.
End If
End If
End If
End If
End If
End If
End If
End If
End If
Next c
prcdExit:
Exit Sub
prcdErr:
Call FatalError(Err.Number, Err.Description, "modListBuilder", "BuildProcessList", False)
Resume prcdExit
End Sub