Hi All,
I've got a piece of VBA that I've developed that works perfectly fine apart from being slow why has to work on a lot of data at once.
I know there will be a way to tidy this up and make it smaller however its out of my skill range at the moment.
I would greatly appreciate anyone who can tidy this up so it runs faster
Sub Button1_Click()
Dim i, lastRow
lastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Application.DisplayAlerts = False
Range("G2:G" & lastRow).Select
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("G2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*SIM*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("SIM").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*SSN*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("SIM").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Sim*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("SIM").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Duplicate*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("Duplicate Account").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Dispute*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("Dispute").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Unlatching*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("Unlatching").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Port*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("Port In").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Age Verification*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("Age Verification").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Direct Debit*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("DD Date Change").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*DISE to Pay*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("DISE Migration").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
lastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To lastRow
Sheets("Sheet1").Columns("I:I").Select
Selection.ClearContents
Sheets("Sheet1").Cells(i, "A").Columns("A:H").ClearContents
Next i
Range("A1").Select
' Show summary message
MsgBox "Finished" _
End Sub
I've got a piece of VBA that I've developed that works perfectly fine apart from being slow why has to work on a lot of data at once.
I know there will be a way to tidy this up and make it smaller however its out of my skill range at the moment.
I would greatly appreciate anyone who can tidy this up so it runs faster
Sub Button1_Click()
Dim i, lastRow
lastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Application.DisplayAlerts = False
Range("G2:G" & lastRow).Select
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("G2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*SIM*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("SIM").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*SSN*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("SIM").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Sim*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("SIM").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Duplicate*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("Duplicate Account").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Dispute*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("Dispute").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Unlatching*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("Unlatching").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Port*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("Port In").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Age Verification*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("Age Verification").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*Direct Debit*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("DD Date Change").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
For i = 2 To lastRow
If Sheets("Sheet1").Cells(i, "A").Value Like "*DISE to Pay*" Then
Sheets("Sheet1").Cells(i, "A").Columns("A:H").Copy Destination:=Sheets("DISE Migration").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
lastRow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To lastRow
Sheets("Sheet1").Columns("I:I").Select
Selection.ClearContents
Sheets("Sheet1").Cells(i, "A").Columns("A:H").ClearContents
Next i
Range("A1").Select
' Show summary message
MsgBox "Finished" _
End Sub