Syntax Sucks!

Bennyton

New Member
Joined
Apr 13, 2011
Messages
20
Hey all. can anyone tell me whats wrong with this?

Sub StopFind()
'
'
'
Sheets("combine450_60 level").Select
Columns("A:D").Select
Selection.ClearContents
Windows("60 STOP macro.xls").Activate
Range("A:A,G:G").Select
Range("G1").Activate
Selection.Copy
Windows("MATT NOT SAP MACRO1.xls").Activate
Range("A1").Select
ActiveSheet.Paste
Windows("450 STOP macro.XLS").Activate
Range("A:A,G:G").Select
Range("G1").Activate
Application.CutCopyMode = False
Selection.Copy
Windows("MATT NOT SAP MACRO1.xls").Activate
Range("C1").Select
ActiveSheet.Paste
'
'Test to search for stop statuses in "combine450_60 level"
'when it finds a stop status, it compares the serial number next to it, to those in column A in the WIP work sheet
'if it finds a match, it will copy and paste that column into the "stop sap or matt" sheet,
'and delete the row from the WIP sheet
SerialCol = "A"
SerialCol1 = "C"
crit1 = "STOP"

Dim CellR As Range
Dim strName As String
Dim Arr() As String

lastRow1 = Sheets("stop sap or matt").Range("A1").End(xlDown).Row


lastRow2 = Sheets("WIP").Range("A1").End(xlDown).Row

lastRow3 = Sheets("combine450_60 level").Range("A1").End(xlDown).Row
For i = 1 To lastRow3

lastRow4 = Sheets("combine450_60 level").Range("C1").End(xlDown).Row
For h = 1 To lastRow4

If Sheets("combine450_60 level").Cells(i, "B").Value = crit1 Then
For j = 1 To lastRow2
If Sheets("WIP").Cells(j, SerialCol).Value = Sheets("combine450_60 level").Cells(i, SerialCol).Value Then
Sheets("WIP").Rows(j).EntireRow.Cut Sheets("stop sap or matt").Range(lastRow1 + 1 & ":" & lastRow1 + 1)
Sheets("WIP").Rows(j).EntireRow.Delete

End If

Next j

ElseIf Sheets("combine450_60 level").Cells(h, "D").Value = crit1 Then
For j = 1 To lastRow2
If Sheets("WIP").Cells(j, SerialCol).Value = Sheets("combine450_60 level").Cells(h, SerialCol1).Value Then
Sheets("WIP").Rows(j).EntireRow.Cut Sheets("stop sap or matt").Rows(lastRow1 + 1 & ":" & lastRow1 + 1)
Sheets("WIP").Rows(j).EntireRow.Delete
End If
Next j
Next h
Next i
End If
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Actually Andrew, I just tried that, and it seemed to run, but caused excel to crash....


the part I'm most worried about is the ElseIf part.

could you have another look please?

Code:
Sub StopFind()
'
'
'
Sheets("combine450_60 level").Select
Columns("A:D").Select
Selection.ClearContents
Windows("60 STOP macro.xls").Activate
Range("A:A,G:G").Select
Range("G1").Activate
Selection.Copy
Windows("MATT NOT SAP MACRO1.xls").Activate
Range("A1").Select
ActiveSheet.Paste
Windows("450 STOP macro.XLS").Activate
Range("A:A,G:G").Select
Range("G1").Activate
Application.CutCopyMode = False
Selection.Copy
Windows("MATT NOT SAP MACRO1.xls").Activate
Range("C1").Select
ActiveSheet.Paste
'
'Test to search for stop statuses in "combine450_60 level"
'when it finds a stop status, it compares the serial number next to it, to those in column A in the WIP work sheet
'if it finds a match, it will copy and paste that column into the "stop sap or matt" sheet,
'and delete the row from the WIP sheet
SerialCol = "A"
SerialCol1 = "C"
crit1 = "STOP"

Dim CellR As Range
Dim strName As String
Dim Arr() As String
            
            lastRow1 = Sheets("stop sap or matt").Range("A1").End(xlDown).Row
            
            
            lastRow2 = Sheets("WIP").Range("A1").End(xlDown).Row
            
            lastRow3 = Sheets("combine450_60 level").Range("A1").End(xlDown).Row
            For i = 1 To lastRow3
            
            lastRow4 = Sheets("combine450_60 level").Range("C1").End(xlDown).Row
            For h = 1 To lastRow4

                     If Sheets("combine450_60 level").Cells(i, "B").Value = crit1 Then
             For j = 1 To lastRow2
                        If Sheets("WIP").Cells(j, SerialCol).Value = Sheets("combine450_60 level").Cells(i, SerialCol).Value Then
                       Sheets("WIP").Rows(j).EntireRow.Cut Sheets("stop sap or matt").Range(lastRow1 + 1 & ":" & lastRow1 + 1)
                       Sheets("WIP").Rows(j).EntireRow.Delete

        End If
  Next j

                       ElseIf Sheets("combine450_60 level").Cells(h, "D").Value = crit1 Then
                     For j = 1 To lastRow2
                If Sheets("WIP").Cells(j, SerialCol).Value = Sheets("combine450_60 level").Cells(h, SerialCol1).Value Then
                Sheets("WIP").Rows(j).EntireRow.Cut Sheets("stop sap or matt").Rows(lastRow1 + 1 & ":" & lastRow1 + 1)
            Sheets("WIP").Rows(j).EntireRow.Delete
        End If
  Next j
End If
  Next h
Next i
                
End If
            
End Sub
thanks
 
Last edited:
Upvote 0
I'm not sure why, but it crashed the whole lot of excel, rather than just the macro part.



I was wondering, would it be possible to take the information from column's C&D and paste them onto the end of A&B, and change the code to just perform the search with those two columns?
 
Upvote 0
Yup.

Well, there are 3 worksheets,

the first one is called " Stop SAP & Matt"

the second is called "WIP"

the third is called "Combine450_60 level"

What I'm trying to do, is import 4 columns of data into the third worksheet...

then I want to check column A's values (serial code's) against those in column A in WIP, as long as colimn B says "STOP"

But I also need to check column C's values (serial code's) against those in column A in WIP, as long as colimn D says "STOP"

if it finds a match, it takes that row out of WIP, and pastes in the last row of Stop SAP & MATT

It then deletes the same row from WIP.

It actually worked yesterday for column A and C...

but I can't get it working now...since I introduced H....

if that makes any sense...


Thanks a million for your time btw
 
Upvote 0

Forum statistics

Threads
1,224,503
Messages
6,179,136
Members
452,890
Latest member
Nikhil Ramesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top