+ Reply to Thread
Results 1 to 5 of 5

VBA Code to run a macro on 2 sheets in same workbook

  1. #1
    Registered User
    Join Date
    06-10-2013
    Location
    NZ
    MS-Off Ver
    Excel 2013
    Posts
    6

    VBA Code to run a macro on 2 sheets in same workbook

    Hi

    I have no experience with VBA at all & have spent hours on the web trying to find out how to do something I imagine is very simple...

    I have 3 sheets in a workbook named "General Invoice", "Itemised Invoice" & "Drop Down Lists". On "General Invoice" & "Itemised Invoice" I want to generate the same invoice number in cell D3. I have used this code to generate an invoice number & clear contents (following a podcast by Mr Excel) which I have attached to a shape:

    Sub NextInvoice()
    Range("D3").Value = Range("D3").Value + 1
    Range("A10:C21").ClearContents
    End Sub

    However it only updates the cell D3 on the sheet the shape is pasted in, not both sheets. How do I make it update both sheets at same time?

    Also how do I clear the contents in cells A4,A6 & A10:C21 on "itemised Invoice" but on "General Invoice" I want to clear A4,A6 & A10:D21 instead?

    Thank you.

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

    Re: VBA Code to run a macro on 2 sheets in same workbook

    Replace your current code with the below one

    Please Login or Register  to view this content.


    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

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: VBA Code to run a macro on 2 sheets in same workbook

    Hello cne73,

    Welcome to the Forum.

    Please adhere to the Forum Rules regarding wrapping of Code.

    Could you also upload a sample WorkBook for us to have a look at for you?

    Chances are far better to get the right solution to your problem.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Registered User
    Join Date
    06-28-2010
    Location
    Posen, Poland
    MS-Off Ver
    Excel 2000
    Posts
    46

    Re: VBA Code to run a macro on 2 sheets in same workbook

    Hi,
    in both sheet at the same time, maybe try something like this:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-10-2013
    Location
    NZ
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: VBA Code to run a macro on 2 sheets in same workbook

    Thank you. Have got it working.

+ 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