Error sorting data compile error

bergsh

New Member
Joined
Sep 12, 2006
Messages
13
Here is my code, I am getting an compile error Next witout For. I do not have all of the worksheet names in the workbook. Is there a way to skip over them and proceed to the next worksheet name? Thanks for the help in advance.


<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Disperse_Data()
<SPAN style="color:#007F00">'</SPAN>
<SPAN style="color:#007F00">' Disperse_Data Macro</SPAN>
<SPAN style="color:#007F00">' Macro recorded 9/14/2006 by Goodyear Tire and Rubber Co</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet

<SPAN style="color:#007F00">'</SPAN>
    Workbooks.Open Filename:= _
        "C:\Documents and Settings\Shawn Berg\My Documents\AC Hose Dimensional Data.xls"
   <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> ActiveWorkbook.Worksheets
     <SPAN style="color:#00007F">If</SPAN> ws.Name = "     4828-010O" <SPAN style="color:#00007F">Then</SPAN>
    Range("B1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Range("A1").Select
    ActiveSheet.Paste
    ws.Name = "     428-010I"
        Range("C1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("C1").Select
        ActiveSheet.Paste
    ws.Name = "     428-010V"
        Range("C1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("D1").Select
        ActiveSheet.Paste
     <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
   <SPAN style="color:#00007F">Next</SPAN> ws
    <SPAN style="color:#00007F">If</SPAN> ws.Name = "     4826-010O" <SPAN style="color:#00007F">Then</SPAN>
    Range("B1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Range("A1").Select
    ActiveSheet.Paste
    ws.Name = "     426-010I"
        Range("C1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("C1").Select
        ActiveSheet.Paste
    ws.Name = "     426-010V"
        Range("C1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("D1").Select
        ActiveSheet.Paste
     <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
   <SPAN style="color:#00007F">Next</SPAN> ws
    <SPAN style="color:#00007F">If</SPAN> ws.Name = "     4826-013O" <SPAN style="color:#00007F">Then</SPAN>
    Range("B1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Range("A1").Select
    ActiveSheet.Paste
    ws.Name = "     426-013I"
        Range("C1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("C1").Select
        ActiveSheet.Paste
    ws.Name = "     426-013V"
        Range("C1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("D1").Select
        ActiveSheet.Paste
     <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
Hi

How about changing it to

Code:
Sub Disperse_Data()
'
' Disperse_Data Macro
' Macro recorded 9/14/2006 by Goodyear Tire and Rubber Co
Dim ws As Worksheet

'
    Workbooks.Open Filename:= _
        "C:\Documents and Settings\Shawn Berg\My Documents\AC Hose Dimensional Data.xls"
   For Each ws In ActiveWorkbook.Worksheets
     If ws.Name = "     4828-010O" Then
    Range("B1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Range("A1").Select
    ActiveSheet.Paste
    ws.Name = "     428-010I"
        Range("C1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("C1").Select
        ActiveSheet.Paste
    ws.Name = "     428-010V"
        Range("C1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("D1").Select
        ActiveSheet.Paste
     End If
   'Next ws
    If ws.Name = "     4826-010O" Then
    Range("B1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Range("A1").Select
    ActiveSheet.Paste
    ws.Name = "     426-010I"
        Range("C1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("C1").Select
        ActiveSheet.Paste
    ws.Name = "     426-010V"
        Range("C1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("D1").Select
        ActiveSheet.Paste
     End If
   'Next ws
    If ws.Name = "     4826-013O" Then
    Range("B1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Range("A1").Select
    ActiveSheet.Paste
    ws.Name = "     426-013I"
        Range("C1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("C1").Select
        ActiveSheet.Paste
    ws.Name = "     426-013V"
        Range("C1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        Range("D1").Select
        ActiveSheet.Paste
     End If
    Next ws
End Sub

Tony
 

Forum statistics

Threads
1,141,934
Messages
5,709,417
Members
421,635
Latest member
mehdi hannechi

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
Top