need to learn IF

agas

New Member
Joined
Mar 22, 2011
Messages
41
I have a workbook with 3 or more worksheets. That depends on the week. The first 2 sheets name doesnt change. So how can i make a check and run a macro for the sheets after the second one. The macro doesnt run for the first 2 sheet but runs for the remaning of the sheets.

Thanks in advance.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Example:

Code:
Sub MyMacro()
    Dim ws As Worksheet
    For Each ws in ThisWorkbook.Worksheets
        If ws.Name <> "Sheet1" And ws.Name <> "Sheet2" Then
            With ws
'                Replace next line with your code
                 MsgBox ws.Name
            End With
        End If
    Next ws
End Sub
 
Upvote 0
Perhaps like this

Code:
For i = 3 To Worksheets.Count
    With Sheets(i)
    '
    'your code here
    '
    End With
Next i
 
Upvote 0
Thank you very much :) It is working great.

Is there a way to get it save the file in the specified user directory.
Let me explain;

I am using this for saving
Code:
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\""USERNAME"\Desktop\cap rep\1\" & "AAP_TK_LO_CAP_REP.xls (" & Format(Date, "dd-mm-yyyy") & ").xls" _
    , FileFormat:=xlExcel8, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False

Can make it use the current logged on users name in "USERNAME" ?
 
Upvote 0
Try

Code:
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\" & Environ("USERNAME") & "\Desktop\cap rep\1\" & "AAP_TK_LO_CAP_REP.xls (" & Format(Date, "dd-mm-yyyy") & ").xls" _
    , FileFormat:=xlExcel8, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
 
Upvote 0
Try this (untested but it should work):

Code:
ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\" & Environ("Username")& "\Desktop\cap rep\1\" & "AAP_TK_LO_CAP_REP.xls (" & Format(Date, "dd-mm-yyyy") & ").xls" _
    , FileFormat:=xlExcel8, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False

Do you KNOW that each user has the folder structure on their desktops? If they don't, this will fall over.
 
Upvote 0
It is working thank you very much :)

I can make them create the folders needed. I just dont want to change the code for every other user.
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

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