+ Reply to Thread
Results 1 to 19 of 19

I need a macro to run on all sheets in a workbook, not just the first.

  1. #1
    Registered User
    Join Date
    07-16-2010
    Location
    Perth Australia
    MS-Off Ver
    Excel 2010
    Posts
    17

    I need a macro to run on all sheets in a workbook, not just the first.

    I have a workbook with currently about 30 worksheets in, although this may vary over time. I have recorded a macro to change a formula to a value which works fine on the first sheet but doesn't work on subsequent sheets. I've assigned the macro to a button i have on all sheets but the macro only works on the first sheet. My basic knowledge of VBA doesn't run to this yet. Thanks.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi, PJMcDonald,

    you should show the code of your macro.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Please post your code so that we can fix it


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Registered User
    Join Date
    07-16-2010
    Location
    Perth Australia
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi, Thanks for your replies. Here is the code.

    Sub formulatovalue()
    '
    ' formulatovalue Macro

    'Application.Workbook.("rollinghandicap2013.xlsx")
    Range("V23").Select
    Selection.AutoFill Destination:=Range("V23:V24"), Type:=xlFillDefault
    Range("$V23:$V24").Select
    Range("$V23").Select
    Range("$V23").Copy
    Range("$V23").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    End Sub

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi, PJMcDonald,

    try
    Please Login or Register  to view this content.
    Could you please wrap Code-Tags around the procedure? Thanks.

    Ciao,
    Holger

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Try this...

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    07-16-2010
    Location
    Perth Australia
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Thanks for your replies,

    One thing I forgot to include was that the active cell references (V23:V24) will move down the page weekly or longer so that the next instance of data being entered will be V25 which will require V24 to change to a value and so on.

    Thanks again.

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    May be this..

    change this

    Please Login or Register  to view this content.
    To

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-16-2010
    Location
    Perth Australia
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi, This is my code as it now stands:

    [Sub formulatovalue2()
    '
    ' formulatovalue Macro

    'Application.Workbook.("rollinghandicap2013.xlsx")
    With ActiveSheet
    .Cells(.Cells(Rows.Count, "V").End(xlUp).Row + 1, "V").FillDown
    .Range("V23:V24").Value = .Range("V23:V24").Value
    End With
    End Sub
    '
    'End Sub]

    It doesn't work at all.

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi, PJMcDonald,

    maybe try
    Please Login or Register  to view this content.
    Ciao,
    Holger

  11. #11
    Registered User
    Join Date
    07-16-2010
    Location
    Perth Australia
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi, HaHoBe,

    It still doesn't work. I assign the button to the new macro (No.3) but clicking it does nothing. I'm beginning to think that changing the formula to a value manually would be easier.

  12. #12
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi, PJMcDonald,

    as I donīt know what kind of button you choose Iīll attach a workbook with a Forms-Button where the code is doing fine.

    Ciao,
    Holger
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    07-16-2010
    Location
    Perth Australia
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi,

    This appears to be a forms button which is what I used. When opening this file Excel told me there was insufficient resources to open in full. But (or therefore) assigning the button to the macro didn't change the result - no change.

    PJ.

  14. #14
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi, PJ,

    the workbook I loaded up contains one sheet with 2 values and 1 formula (=Row()*Column()), one Forms-Button and one module holding the code - hard to believe that Excel wonīt be able to open a file of 14,8 KB.

    Attached workbook as *.xls.

    Ciao,
    Holger
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    07-16-2010
    Location
    Perth Australia
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi, It's now Saturday morning and this button now works fine. Perhaps my pc needed a reboot yesterday. Still no joy with the formula to value macro 'though. This is the macro as it currently appears.

    [Sub formulatovalue3()
    '
    ' formulatovalue Macro

    'Application.Workbook.("rollinghandicap2013.xlsx")
    With ActiveSheet
    With .Cells(.Cells(Rows.Count, "V").End(xlUp).Row, "V")
    .AutoFill Destination:=.Resize(2, 1), Type:=xlFillDefault
    .Value = .Value
    End With
    End With
    End Sub]

    PJ

  16. #16
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi, PJ,

    do you have the trouble with the sample workbooks or with your own workbook?

    Regarding the code: the Tags to use are [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] . The other way to do is Go Advanced for ansswering, highlight your code and click the # icon at the top of your post window.

    Ciao,
    Holger

  17. #17
    Registered User
    Join Date
    07-16-2010
    Location
    Perth Australia
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi,

    I only have trouble with my workbook. When I started this thread the macro that I recorded worked on the first sheet but not any of the subsequent worksheets. Now the macro (as amended) doesn't work at all.
    Regards.
    PJ

  18. #18
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi, PJ,

    maybe you could attach the workbook for us to have a look at it. If thatīs not possible may copy all the contents into a new workbook and try the code in the new workbook thatīs all I may suggest as by now.

    Ciao,
    Holger

  19. #19
    Registered User
    Join Date
    07-16-2010
    Location
    Perth Australia
    MS-Off Ver
    Excel 2010
    Posts
    17

    Smile Re: I need a macro to run on all sheets in a workbook, not just the first.

    Hi, The workbook is quite large and has some private info on it so I wont upload it. I'll try to copy it to a new workbook as you suggest. Thanks for your interest.
    PJ

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1