macro: with without for - make cell value footer

oliviar

Board Regular
Joined
Sep 12, 2010
Messages
184
Hy Guys,
I have a 'with without for' error.
I want to make the cell 'rightfooter' on sheet1 the value of the right footer on everysheet. But my cycle through macro is producing a with without for error: :confused:

Code:
Sub rightfooter()
Application.ScreenUpdating = False
    Sheets("sheet2").Visible = True
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        r = Worksheets("Sheet1").Range("rightfooter")
    With ActiveSheet.PageSetup
        .RightFooter = r
    Next ws
    Sheets("sheet1").Select
    Application.ScreenUpdating = True
End Sub

Please help, thanks
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi oliviar,

You're missing an End With. Putting this line of code...

Code:
End With

...immediately beneath this line of code:

Code:
.RightFooter = r

should do the trick.

HTH

Robert
 
Upvote 0
Still issues...
Code:
Sub rightfooter1()
Application.ScreenUpdating = False
    Sheets("sheet2").Visible = True
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
    With ActiveSheet.PageSetup
    r = Worksheets("Sheet1").Range("rightfooter")
        .RightFooter = r
        End With
    Next ws
    Sheets("sheet1").Select
    Application.ScreenUpdating = True
End Sub

It is only updating the value on sheet 1 and none of the others. ?
 
Upvote 0
Try this:

Code:
Sub Macro3()

    Application.ScreenUpdating = False
    
    Sheets("sheet2").Visible = True
        
    For Each Worksheet In ActiveWorkbook.Worksheets
        With Worksheet.PageSetup
            .RightFooter = Range("rightfooter")
        End With
    Next Worksheet
    
    Application.ScreenUpdating = True

End Sub

HTH

Robert
 
Upvote 0
Thank you that worked.
Plus I found out I had a strange thing happening... my sheet was set to calculate manually. So I also wrote into the macro to force it to be calculating automatically.
 
Upvote 0
That's good ;)

Unless the code is switching the calculation mode to manual, manually setting it once to automatic should just keep it there. Also, you may not need this line of code...

Code:
Sheets("sheet2").Visible = True

...as part of the macro as once the tab is visible it stays visible.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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