Copy worksheet and update

padadof2

New Member
Joined
Jan 11, 2010
Messages
44
I have a billing estimate workbook that we use for our projects. I'd like to be able to use VBA to copy the old worksheet to a new worksheet and update the numbers. We have Columns H/I that are the Previous billing quantity/Amount that has to be copied from the previous worksheet. We have columns J/K that are this application totals, Columns L/M are completed to date numbers which always have to be updated and then finally we have a Balance to finish columns N/O. The two cells are Quantity/Amount for each of the Billings. What I would like to accomplish, is being able to hit a macro button and the newest sheet in the workbook is copied, renamed to Estimate (X), and all the info from columns J/K are copied and pasted into H/I. With each new worksheet, I'd like to have columns L/M & N/O updated with each new sheet. I've attached a sample. I'm struggling how to keep a running total on the completed to date columns (L/M) and the Balance to Finish Columns (N/O)

Here is the code that I've pulled that allows me to copy a new worksheet and update the links, but it only works once, and then it zeros columns out.

VBA Code:
Sub NewEstimate()

Dim h As Long, i As Long, u As Long
Dim sc As Long, sc1 As Long, sc2 As Long
Dim endrow As Long

endrow = Sheets(1).Cells(Rows.Count, 1).End(3).Row

h = 15
sc = Sheets.Count
h = h + 15

Sheets(1).Copy After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).DisplayRightToLeft = False
sc2 = Sheets.Count

If sc2 > sc1 Then
    u = h - 13
    Sheets(Sheets.Count).Name = "ESTIMATE" + Str(sc2 - 1)
End If

For i = 2 To Sheets.Count
    Sheets(i).Range("z2") = i - 1
    Sheets(i).Range("ab2") = Sheets.Count - 1
Next

Sheets(Sheets.Count - 1).Range("I11:I126").Copy
Sheets(Sheets.Count).Range("G11:G126").PasteSpecial xlPasteAll

Sheets(Sheets.Count).Range("I11:I126").ClearContents


End Sub

Here is a sample of the billing.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
dont give up, i cannot download at work, will do a workaround and check it tomorrow
 
Upvote 0
Hi padaof2,

the file hasn't any macro (not that i would enable it :) ).
I write my own, and maybe simplified too much, also adjusted the "bill" formula:
sample billing(2) (version 2).xlsb
BCDEFGHIJKLMNO
6CONTRACT INFORMATIONBILLING INFORMATION
7BID TOTALPreviousThis ApplicationCompleted to DateBalance to Finish
8ITEMDESCRIPTIONQUANUNITCOSTAMOUNTQuantityAmountQuantityAmountQuantityAmountQuantityAmount
919axel10EA $ 5 000,00 $ 50 000,00 0,00 $ - 3,00 $ 15 000,00 3,00 $ 15 000,00 7,00 $ 35 000,00
1020Wheels5EA $ 1 000,00 $ 5 000,00 0,00 $ - 1,00 $ 1 000,00 1,00 $ 1 000,00 4,00 $ 4 000,00
bill1
Cell Formulas
RangeFormula
K9:K10K9=F9*J9
L9:L10L9=J9
M9:M10M9=L9*F9
N9:N10N9=D9-L9
O9:O10O9=N9*F9
G9:G10G9=D9*F9
I9:I10I9=H9*F9


Make a box/button to first sheet (or if you have a form) and assign this code to it
VBA Code:
Sub padadof2_new_estamination()
Application.ScreenUpdating = False
'https://www.mrexcel.com/board/threads/copy-worksheet-and-update.1122531/#post-5424617

asn = ActiveSheet.Name
Sheets(asn).Copy After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Select
ActiveSheet.Name = "Estamination " & Sheets.Count
Range("J9:J126").Copy
Range("H9:H126").PasteSpecial xlPasteValues
Range("L9:L126").PasteSpecial xlPasteValues, Operation:=xlAdd
'Range("L9:L126").Value = Range("L9:L126").Value 'optional
Range("J9:J126").ClearContents
Application.ScreenUpdating = True
End Sub

I hope that helps.
The "optional" line maybe needed. The adding values to "completed" column will show how many times and what values added to it (for each estamination)
(btw the 3rd sheet in your wb is miscalculate the completed items, because adding the previous deliver 2 times)
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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