One code updates two worksheets

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,699
Office Version
  1. 2007
Platform
  1. Windows
Morning,
I have the following supplied code which works fine.
The worksheet that this code is on is named INVOICE.
I have copied this worksheet & named it INVOICE 2

What i would like to do is after the current invoice number has incremented by 1 on INVOICE 1 have the same happen for INVOICE 2
If you can advise i will the also add this code to INVOICE 2 to do the same for INVOICE

Range("N4").Value = Range("N4").Value + 1 worksheet ="INVOICE2" ETC ETC

Code:
Private Sub Clear_Invoice_After_Printing_Click()    
    Dim objWord As New Word.Application
    'Copy the range Which you want to paste in a New Word Document as a screenshot
    Dim strFileName As String
    strFileName = "C:\Users\Ian\Desktop\REMOTES ETC\DR COPY INVOICES\Invoice " & Range("N4").Value & " " & Format(Now, "dd-mm-yyyy") & ".doc"
    Range("G3:O60").CopyPicture xlPrinter
    With objWord
        With .Documents.Add
            .Parent.Selection.Paste
            .SaveAs strFileName
            .Close
        End With
        '.Visible = True
        .Quit
    End With
    MsgBox strFileName, vbInformation, "Invoice Saved as Screenshot  Word.doc"
    
    
    Range("G13:I18").ClearContents
    Range("N14:O18").ClearContents
    Range("G27:N42").ClearContents
    Range("G13:I13").ClearContents
    Range("G49:I49").ClearContents
    Range("G48:I48").ClearContents
    Range("G47:I47").ClearContents
    Range("G46:I46").ClearContents
    Range("G45:I45").ClearContents
    Range("N4").Value = Range("N4").Value + 1
    Range("G13").Select
    ActiveWorkbook.Save
    
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
What you ask seems almost too easy which makes me think I've misunderstood. So If the cell containing the current invoice number changes, change the equivalent cell on 2 other worksheets to the exact same number?
 
Upvote 0
Hi,
On INVOICE sheet the number changed as they are printed off
At the point the sheet INVOICE 2 also needs to follow suit without me even opening the INVOICE 2 sheet.

Example.
Both sheets are at say 100

I then print off 4 invoices using INVOICE "BUT" i also require INVOICE to to show 104 even though this sheet was not opened.

Hence the code running on INVOICE not only does it increment that sheet but also INVOICE 2 sheet.

Thanks
 
Upvote 0
Ahh, You're getting mixed up between workbooks and worksheets. Workbooks contain worksheets. I thought you just needed to update a value in the same workbook.

So is the invoice number in the exact same location on in each workbook?

If so what are the workbook names, worksheet names and cell addresses? It's still straight forward, just need that info
 
Upvote 0
I assume you know you can just link the cells. Will it always be INVOICE that changes then the next 2 need updating?
 
Upvote 0
No i did not know.
Two worksheets.
INVOICE & INVOICE 2

When the receipt number changes on one i need it to also do the same for the other,then i will not have 2 receipts the same number.
 
Upvote 0
Will it always be INVOICE that changes and INVOICE 2 that needs updating or could INVOICE 2 change and INVOICE need updating too?

If only INVOICE 2 needs to reflect then:


  1. Open both INVOICE + INVOICE 2
  2. On INVOICE 2 go to the cell that contains the invoice number (i assume it is the same as INVOICE - N4 ?)
  3. In the formula bar type =
  4. Then click on INVOICE and click on N4 and press enter.
  5. The formula on N4 on INVOICE 2 should read something like:
    Code:
    =[INVOICE.xlsx]Sheet1!$N$4

If you have the same Macro on each sheet then we need to do it in code...
 
Upvote 0
I think this will produce what im looking for ??

Code:
Worksheets("INVOICE 2").Range("N4").Value = Range("N4").Value
 
Upvote 0
It is,

Many thanks for your time.

I will also look at your code supplied.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
Members
452,363
Latest member
merico17

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