Hi everyone
I copied the following code from a YouTube tutorial:
The code does as instructed but the workbook is very slow and sometimes crashes. I am using =XLOOKUP formula to retrieve data from another workbook called Mail Merge Data to return a customer's name, address, suburb, and postcode. Can anyone advise how this can be improved/simplified so that the workbook isn't so slow?
Occasionally, we need to paste "DESTROY" not "destroy" in the override column, but I haven't been able to work out how to get VBA to ignore whether the text is upper case or lower case. Furthermore, as I have saved the template and the mail merge data in Sharepoint via Microsoft Teams, Excel makes me keep the mail merge data as a separate tab on the template workbook.
Thanks for your help in advance.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Not my code. This was taken from YouTube
a = Worksheets("Merge").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To a
If Worksheets("Merge").Cells(i, 7).Value = "destroy" Then
Worksheets("Merge").Rows(i).Cut
Worksheets("Reject").Activate
b = Worksheets("Reject").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Reject").Cells(b + 1, 1).Select
ActiveSheet.Paste
Worksheets("Merge").Activate
End If
Next
For i = 2 To a
If Worksheets("Merge").Cells(i, 1).Value = "" Then
Rows(i).Delete
End If
Next
For i = 2 To a
If Worksheets("Merge").Cells(i, 7).Value = "-" Then
Worksheets("Merge").Rows(i).Cut
Worksheets("Send").Activate
c = Worksheets("Send").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Send").Cells(c + 1, 1).Select
ActiveSheet.Paste
Worksheets("Merge").Activate
End If
Next
Worksheets("Merge").Columns.AutoFit
Worksheets("Merge").Rows.AutoFit
Worksheets("Send").Columns.AutoFit
Worksheets("Send").Rows.AutoFit
Worksheets("Reject").Columns.AutoFit
Worksheets("Reject").Rows.AutoFit
End Sub
I copied the following code from a YouTube tutorial:
The code does as instructed but the workbook is very slow and sometimes crashes. I am using =XLOOKUP formula to retrieve data from another workbook called Mail Merge Data to return a customer's name, address, suburb, and postcode. Can anyone advise how this can be improved/simplified so that the workbook isn't so slow?
Occasionally, we need to paste "DESTROY" not "destroy" in the override column, but I haven't been able to work out how to get VBA to ignore whether the text is upper case or lower case. Furthermore, as I have saved the template and the mail merge data in Sharepoint via Microsoft Teams, Excel makes me keep the mail merge data as a separate tab on the template workbook.
Thanks for your help in advance.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Not my code. This was taken from YouTube
a = Worksheets("Merge").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To a
If Worksheets("Merge").Cells(i, 7).Value = "destroy" Then
Worksheets("Merge").Rows(i).Cut
Worksheets("Reject").Activate
b = Worksheets("Reject").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Reject").Cells(b + 1, 1).Select
ActiveSheet.Paste
Worksheets("Merge").Activate
End If
Next
For i = 2 To a
If Worksheets("Merge").Cells(i, 1).Value = "" Then
Rows(i).Delete
End If
Next
For i = 2 To a
If Worksheets("Merge").Cells(i, 7).Value = "-" Then
Worksheets("Merge").Rows(i).Cut
Worksheets("Send").Activate
c = Worksheets("Send").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Send").Cells(c + 1, 1).Select
ActiveSheet.Paste
Worksheets("Merge").Activate
End If
Next
Worksheets("Merge").Columns.AutoFit
Worksheets("Merge").Rows.AutoFit
Worksheets("Send").Columns.AutoFit
Worksheets("Send").Rows.AutoFit
Worksheets("Reject").Columns.AutoFit
Worksheets("Reject").Rows.AutoFit
End Sub