matthewrlong
New Member
- Joined
- Jan 18, 2017
- Messages
- 11
Hey Everyone,
I have been trying to figure out how to make a button that will copy specific rows (A6:L6 and down) from "Optimization Ticket".
This sheet could have 5 rows filled in or 50 rows filled in.
These rows will land in "Process Ticket" starting at cell A2.
This is what I have so far.
Trust me when I tell you, I am a novice.

Option Explicit
Sub CommandButton2_Click()
Dim lastRow As Long, i As Long
Dim CopyRange As Range
With Sheets("Optimization Ticket")
lastRow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 2 To lastRow
If Len(Trim(.Range("A" & i).Value)) <> 0 Then
If CopyRange Is Nothing Then
Set CopyRange = .Rows(i)
Else
Set CopyRange = Union(CopyRange, .Rows(i))
End If
Else
Exit For
End If
Next
If Not CopyRange Is Nothing Then
CopyRange.Copy Sheets("Process Ticket").Rows(1)
End If
End With
End Sub
Thank you
ML
I have been trying to figure out how to make a button that will copy specific rows (A6:L6 and down) from "Optimization Ticket".
This sheet could have 5 rows filled in or 50 rows filled in.
These rows will land in "Process Ticket" starting at cell A2.
This is what I have so far.
Trust me when I tell you, I am a novice.


Option Explicit
Sub CommandButton2_Click()
Dim lastRow As Long, i As Long
Dim CopyRange As Range
With Sheets("Optimization Ticket")
lastRow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 2 To lastRow
If Len(Trim(.Range("A" & i).Value)) <> 0 Then
If CopyRange Is Nothing Then
Set CopyRange = .Rows(i)
Else
Set CopyRange = Union(CopyRange, .Rows(i))
End If
Else
Exit For
End If
Next
If Not CopyRange Is Nothing Then
CopyRange.Copy Sheets("Process Ticket").Rows(1)
End If
End With
End Sub
Thank you
ML