Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o> </o>
I am trying to get the following code to compare two ranges. If they are the same then the cell "y" is to be deleted, but I also want to delete the two adjacent cells y.offset(0, 1) and y.offset(0, 2). When I try to do any of these individually it works but when I try and follow the Then statement with instructions to delete all it doesn't work. The relevant section of code is below with the complete code at the bottom for reference.<o></o>
<o></o>
Tabledim = Application.CountA(Sheets("Main").Range("A1:A1000"))<o></o>
Dim CompareRange As Variant, x As Variant, y As Variant<o></o>
Dim a As Integer<o></o>
<o></o>
<o></o>
For i = 2 To Tabledim<o></o>
If Cells(i, 2) = "Pre-Starting" Then<o></o>
Set CompareRange = Sheets("All Guides").Range("A3:A500")<o></o>
Sheets("Main").Cells(i, 1).Select<o></o>
For Each x In Selection<o></o>
For Each y In CompareRange<o></o>
If x = y Then y.Delete<o></o>
Next y<o></o>
Next x<o></o>
End If<o></o>
Next i<o></o>
<o> </o>
When I try to use<o></o>
<o> </o>
If x = y Then y.Delete: y.Offset(0, 1).Delete: y.Offset(0, 2).Delete<o></o>
<o> </o>
I get the message Error 424: An object is required, with ": y.Offset(0, 1).Delete" highlighted in the code.<o></o>
<o> </o>
When I try to use<o></o>
<o> </o>
If x = y Then <o></o>
y.Delete <o></o>
y.Offset(0, 1).Delete <o></o>
y.Offset(0, 2).Delete<o></o>
<o> </o>
I get the message Compilation Error: Next without For, with the "next" of "next y" highlighted.<o></o>
<o> </o>
Any help solving this would be much appreciated. I'm pretty new to this so it may be something stupid. Thanks very much.<o></o>
<o> </o>
Calum<o></o>
<o> </o>
<o> </o>
<o> </o>
Sub FindGuides()'<o></o>
<o> </o>
Sheets("Pre-Starting").Cells.ClearContents<o></o>
<o></o>
Sheets("Starting").Cells.ClearContents<o></o>
<o></o>
Sheets("turning").Cells.ClearContents<o></o>
<o></o>
Sheets("Vantage").Cells.ClearContents<o></o>
<o></o>
Sheets("Power").Cells.ClearContents <o></o>
<o></o>
Sheets("Maintenance").Range("A1:AD500").Copy Destination:=Sheets("All Guides").Range("A1:AD500")<o></o>
<o></o>
<o></o>
Tabledim = Application.CountA(Sheets("Main").Range("A1:A1000"))<o></o>
Dim CompareRange As Variant, x As Variant, y As Variant<o></o>
Dim a As Integer<o></o>
<o></o>
<o></o>
For i = 2 To Tabledim<o></o>
If Cells(i, 2) = "Pre-Starting" Then<o></o>
Set CompareRange = Sheets("All Guides").Range("A3:A500")<o></o>
Sheets("Main").Cells(i, 1).Select<o></o>
For Each x In Selection<o></o>
For Each y In CompareRange<o></o>
If x = y Then y.Delete<o></o>
Next y<o></o>
Next x<o></o>
<o></o>
ElseIf Cells(i, 2) = "Starting" Then<o></o>
Set CompareRange = Sheets("All Guides").Range("G3:G500")<o></o>
Sheets("Main").Cells(i, 1).Select<o></o>
For Each x In Selection<o></o>
For Each y In CompareRange<o></o>
If x = y Then y.Delete<o></o>
Next y<o></o>
Next x<o></o>
<o></o>
ElseIf Cells(i, 2) = "turning" Then<o></o>
Set CompareRange = Sheets("All Guides").Range("M3:M500")<o></o>
Sheets("Main").Cells(i, 1).Select<o></o>
For Each x In Selection<o></o>
For Each y In CompareRange<o></o>
If x = y Then y.Delete<o></o>
Next y<o></o>
Next x<o></o>
<o></o>
ElseIf Cells(i, 2) = "Vantage" Then<o></o>
Set CompareRange = Sheets("All Guides").Range("S3:S500")<o></o>
Sheets("Main").Cells(i, 1).Select<o></o>
For Each x In Selection<o></o>
For Each y In CompareRange<o></o>
If x = y Then y.Delete<o></o>
Next y<o></o>
Next x <o></o>
<o> </o>
ElseIf Cells(i, 2) = "Power" Then<o></o>
Set CompareRange = Sheets("All Guides").Range("Y3:Y500")<o></o>
Sheets("Main").Cells(i, 1).Select<o></o>
For Each x In Selection<o></o>
For Each y In CompareRange<o></o>
If x = y Then y.Delete<o></o>
Next y<o></o>
Next x<o></o>
<o></o>
End If<o></o>
Next i<o></o>
<o></o>
Dim Atabledim As Integer<o></o>
Atabledim = Application.CountA(Sheets("All Guides").Range("A3:A500"))<o></o>
Sheets("All Guides").Activate<o></o>
ActiveSheet.Range(Cells(3, 1), Cells(Atabledim + 2, 3)).Select<o></o>
Selection.Copy<o></o>
Sheets("Pre-Starting").Activate<o></o>
ActiveSheet.Range("A1").Select<o></o>
ActiveSheet.Paste<o></o>
<o></o>
Dim Btabledim As Integer<o></o>
Btabledim = Application.CountA(Sheets("All Guides").Range("G3:G500"))<o></o>
Sheets("All Guides").Activate<o></o>
ActiveSheet.Range(Cells(3, 7), Cells(Btabledim + 2, 9)).Select<o></o>
Selection.Copy<o></o>
Sheets("Starting").Activate<o></o>
ActiveSheet.Range("A1").Select<o></o>
ActiveSheet.Paste<o></o>
<o></o>
Dim Ctabledim As Integer<o></o>
Ctabledim = Application.CountA(Sheets("All Guides").Range("M3:M500"))<o></o>
Sheets("All Guides").Activate<o></o>
ActiveSheet.Range(Cells(3, 13), Cells(Ctabledim + 2, 15)).Select<o></o>
Selection.Copy<o></o>
Sheets("Turning").Activate<o></o>
ActiveSheet.Range("A1").Select<o></o>
ActiveSheet.Paste<o></o>
<o></o>
Dim Dtabledim As Integer<o></o>
Dtabledim = Application.CountA(Sheets("All Guides").Range("S3:S500"))<o></o>
Sheets("All Guides").Activate<o></o>
ActiveSheet.Range(Cells(3, 19), Cells(Dtabledim + 2, 21)).Select<o></o>
Selection.Copy<o></o>
Sheets("Vantage").Activate<o></o>
ActiveSheet.Range("A1").Select<o></o>
ActiveSheet.Paste<o></o>
<o></o>
Dim Etabledim As Integer<o></o>
Etabledim = Application.CountA(Sheets("All Guides").Range("Y3:Y500"))<o></o>
Sheets("All Guides").Activate<o></o>
ActiveSheet.Range(Cells(3, 25), Cells(Etabledim + 2, 27)).Select<o></o>
Selection.Copy<o></o>
Sheets("Power").Activate<o></o>
ActiveSheet.Range("A1").Select<o></o>
ActiveSheet.Paste<o></o>
<o></o>
Sheets("Main").Cells.ClearContents<o></o>
<o></o>
Sheets("Main").Range("A1") = "Paste your register here ya fanny!"<o></o>
With ActiveCell.Characters(Start:=1, Length:=34).Font<o></o>
.Name = "Arial"<o></o>
.FontStyle = "Negrita"<o></o>
.Size = 10<o></o>
.Strikethrough = False<o></o>
.Superscript = False<o></o>
.Subscript = False<o></o>
.OutlineFont = False<o></o>
.Shadow = False<o></o>
.Underline = xlUnderlineStyleNone<o></o>
.ColorIndex = 1<o></o>
End With<o></o>
Sheets("Main").Activate<o></o>
ActiveSheet.Range("A1").Select
End Sub
<o> </o>
I am trying to get the following code to compare two ranges. If they are the same then the cell "y" is to be deleted, but I also want to delete the two adjacent cells y.offset(0, 1) and y.offset(0, 2). When I try to do any of these individually it works but when I try and follow the Then statement with instructions to delete all it doesn't work. The relevant section of code is below with the complete code at the bottom for reference.<o></o>
<o></o>
Tabledim = Application.CountA(Sheets("Main").Range("A1:A1000"))<o></o>
Dim CompareRange As Variant, x As Variant, y As Variant<o></o>
Dim a As Integer<o></o>
<o></o>
<o></o>
For i = 2 To Tabledim<o></o>
If Cells(i, 2) = "Pre-Starting" Then<o></o>
Set CompareRange = Sheets("All Guides").Range("A3:A500")<o></o>
Sheets("Main").Cells(i, 1).Select<o></o>
For Each x In Selection<o></o>
For Each y In CompareRange<o></o>
If x = y Then y.Delete<o></o>
Next y<o></o>
Next x<o></o>
End If<o></o>
Next i<o></o>
<o> </o>
When I try to use<o></o>
<o> </o>
If x = y Then y.Delete: y.Offset(0, 1).Delete: y.Offset(0, 2).Delete<o></o>
<o> </o>
I get the message Error 424: An object is required, with ": y.Offset(0, 1).Delete" highlighted in the code.<o></o>
<o> </o>
When I try to use<o></o>
<o> </o>
If x = y Then <o></o>
y.Delete <o></o>
y.Offset(0, 1).Delete <o></o>
y.Offset(0, 2).Delete<o></o>
<o> </o>
I get the message Compilation Error: Next without For, with the "next" of "next y" highlighted.<o></o>
<o> </o>
Any help solving this would be much appreciated. I'm pretty new to this so it may be something stupid. Thanks very much.<o></o>
<o> </o>
Calum<o></o>
<o> </o>
<o> </o>
<o> </o>
Sub FindGuides()'<o></o>
<o> </o>
Sheets("Pre-Starting").Cells.ClearContents<o></o>
<o></o>
Sheets("Starting").Cells.ClearContents<o></o>
<o></o>
Sheets("turning").Cells.ClearContents<o></o>
<o></o>
Sheets("Vantage").Cells.ClearContents<o></o>
<o></o>
Sheets("Power").Cells.ClearContents <o></o>
<o></o>
Sheets("Maintenance").Range("A1:AD500").Copy Destination:=Sheets("All Guides").Range("A1:AD500")<o></o>
<o></o>
<o></o>
Tabledim = Application.CountA(Sheets("Main").Range("A1:A1000"))<o></o>
Dim CompareRange As Variant, x As Variant, y As Variant<o></o>
Dim a As Integer<o></o>
<o></o>
<o></o>
For i = 2 To Tabledim<o></o>
If Cells(i, 2) = "Pre-Starting" Then<o></o>
Set CompareRange = Sheets("All Guides").Range("A3:A500")<o></o>
Sheets("Main").Cells(i, 1).Select<o></o>
For Each x In Selection<o></o>
For Each y In CompareRange<o></o>
If x = y Then y.Delete<o></o>
Next y<o></o>
Next x<o></o>
<o></o>
ElseIf Cells(i, 2) = "Starting" Then<o></o>
Set CompareRange = Sheets("All Guides").Range("G3:G500")<o></o>
Sheets("Main").Cells(i, 1).Select<o></o>
For Each x In Selection<o></o>
For Each y In CompareRange<o></o>
If x = y Then y.Delete<o></o>
Next y<o></o>
Next x<o></o>
<o></o>
ElseIf Cells(i, 2) = "turning" Then<o></o>
Set CompareRange = Sheets("All Guides").Range("M3:M500")<o></o>
Sheets("Main").Cells(i, 1).Select<o></o>
For Each x In Selection<o></o>
For Each y In CompareRange<o></o>
If x = y Then y.Delete<o></o>
Next y<o></o>
Next x<o></o>
<o></o>
ElseIf Cells(i, 2) = "Vantage" Then<o></o>
Set CompareRange = Sheets("All Guides").Range("S3:S500")<o></o>
Sheets("Main").Cells(i, 1).Select<o></o>
For Each x In Selection<o></o>
For Each y In CompareRange<o></o>
If x = y Then y.Delete<o></o>
Next y<o></o>
Next x <o></o>
<o> </o>
ElseIf Cells(i, 2) = "Power" Then<o></o>
Set CompareRange = Sheets("All Guides").Range("Y3:Y500")<o></o>
Sheets("Main").Cells(i, 1).Select<o></o>
For Each x In Selection<o></o>
For Each y In CompareRange<o></o>
If x = y Then y.Delete<o></o>
Next y<o></o>
Next x<o></o>
<o></o>
End If<o></o>
Next i<o></o>
<o></o>
Dim Atabledim As Integer<o></o>
Atabledim = Application.CountA(Sheets("All Guides").Range("A3:A500"))<o></o>
Sheets("All Guides").Activate<o></o>
ActiveSheet.Range(Cells(3, 1), Cells(Atabledim + 2, 3)).Select<o></o>
Selection.Copy<o></o>
Sheets("Pre-Starting").Activate<o></o>
ActiveSheet.Range("A1").Select<o></o>
ActiveSheet.Paste<o></o>
<o></o>
Dim Btabledim As Integer<o></o>
Btabledim = Application.CountA(Sheets("All Guides").Range("G3:G500"))<o></o>
Sheets("All Guides").Activate<o></o>
ActiveSheet.Range(Cells(3, 7), Cells(Btabledim + 2, 9)).Select<o></o>
Selection.Copy<o></o>
Sheets("Starting").Activate<o></o>
ActiveSheet.Range("A1").Select<o></o>
ActiveSheet.Paste<o></o>
<o></o>
Dim Ctabledim As Integer<o></o>
Ctabledim = Application.CountA(Sheets("All Guides").Range("M3:M500"))<o></o>
Sheets("All Guides").Activate<o></o>
ActiveSheet.Range(Cells(3, 13), Cells(Ctabledim + 2, 15)).Select<o></o>
Selection.Copy<o></o>
Sheets("Turning").Activate<o></o>
ActiveSheet.Range("A1").Select<o></o>
ActiveSheet.Paste<o></o>
<o></o>
Dim Dtabledim As Integer<o></o>
Dtabledim = Application.CountA(Sheets("All Guides").Range("S3:S500"))<o></o>
Sheets("All Guides").Activate<o></o>
ActiveSheet.Range(Cells(3, 19), Cells(Dtabledim + 2, 21)).Select<o></o>
Selection.Copy<o></o>
Sheets("Vantage").Activate<o></o>
ActiveSheet.Range("A1").Select<o></o>
ActiveSheet.Paste<o></o>
<o></o>
Dim Etabledim As Integer<o></o>
Etabledim = Application.CountA(Sheets("All Guides").Range("Y3:Y500"))<o></o>
Sheets("All Guides").Activate<o></o>
ActiveSheet.Range(Cells(3, 25), Cells(Etabledim + 2, 27)).Select<o></o>
Selection.Copy<o></o>
Sheets("Power").Activate<o></o>
ActiveSheet.Range("A1").Select<o></o>
ActiveSheet.Paste<o></o>
<o></o>
Sheets("Main").Cells.ClearContents<o></o>
<o></o>
Sheets("Main").Range("A1") = "Paste your register here ya fanny!"<o></o>
With ActiveCell.Characters(Start:=1, Length:=34).Font<o></o>
.Name = "Arial"<o></o>
.FontStyle = "Negrita"<o></o>
.Size = 10<o></o>
.Strikethrough = False<o></o>
.Superscript = False<o></o>
.Subscript = False<o></o>
.OutlineFont = False<o></o>
.Shadow = False<o></o>
.Underline = xlUnderlineStyleNone<o></o>
.ColorIndex = 1<o></o>
End With<o></o>
Sheets("Main").Activate<o></o>
ActiveSheet.Range("A1").Select
End Sub