Need help with Mac Code

Frank3923

Board Regular
Joined
Jan 20, 2003
Messages
244
I have put together the following code, that is shown below. when I attempt to run it, I get the following error.

Compile error: Next without for

I do have the line, For Each Wks In Worksheets

Being that I am not a programmer, I do not understand, what is needed to fix current error.

Thank you in advance.


Sub Add_the_Formulas()

Dim Wks As Worksheet

Dim lngRow As Long, lngLastRow As Long

For Each Wks In Worksheets

If ws.Name <> "Teams-List" Then
Wks.Select

Range("C1").Formula = "=RIGHT(A1,LEN(A1)-FIND(""^^"",SUBSTITUTE(A1,""_"",""^^"",LEN(A1)-LEN(SUBSTITUTE(A1,""_"","""")))))"

Range("D5").Formula = "=LEFT(C1,LEN(C1)-(LEN(C1)-FIND(""@"",C1)+1))"

Range("D5").Formula = "=RIGHT(C1,LEN(C1)-SEARCH(""@"",C1,1)*1)"


Next Wks

End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Put this

Code:
If ws.Name <> "Teams-List" Then
Wks.Select

all on one line like this

Code:
If ws.Name <> "Teams-List" Then Wks.Select

The way it's written now it looks like the beginning of a block if-then so when it gets to the Next Wks line, it's interpreted as being a child of the block if-then structure but without the For. I think...:)

But, if you intended it to be a block then you just need to add the End If statement.
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,786
Members
452,942
Latest member
VijayNewtoExcel

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