Update data in one sheet with a button based on another workseet

nondigital

New Member
Joined
Aug 30, 2014
Messages
7
I have a worksheet COSTING in which data must be updated from another INPUT sheet every week. I need to have an UPDATE button on top of COSTING sheet so that upon clicking, it can pick data from the INPUT sheet.
COSTING sheet has subsets with subtotal on top of each subset. It looks like this:

Element
DescriptionActual
Committed
Total
PC
Main Costs19841962180
PC-01Equipments34243385
PC-02Services54354597
PC-03Commercial22322245
PC-04Financial87677953
OH
Overheads9999198
OH-1Management5667123
OH-2Admin43043
OH-3Selling03232

<tbody>
</tbody>


the second sheet has the variable date which has same Element number. But there are blank rows and columns in between as it is coming from another program (SAP) It looks like this:

S.No.BlankElementNatureDescriptionActualCommittedTotal
2PC-01aEquipments34243385
Blank
3
PC-02aServices54354597
Blank
4
PC-03aCommercial22322245
Blank
5
PC-04aFinancial87677953
Blank
7
OH-1bManagement5667123
Blank
8
OH-2bAdmin43043
Blank
9
OH-3bSelling03232

<tbody>
</tbody>

<tbody>
</tbody>
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi & welcome to the board.
Should the Costings sheet be overwritten every time, or added to?
 
Upvote 0
Thank you.
Yes. COSTING sheet should be overwritten every time as the second input sheet always has cumulative value.
 
Upvote 0
In that case give this a go
Code:
Sub nondigital()

    Dim InptSht As Worksheet
    Dim CstSht As Worksheet
    Dim PcRws As Long
    Dim OhRws As Long
    Dim UsdRws As Long

Application.ScreenUpdating = False
    Set InptSht = Worksheets("INPUT")
    Set CstSht = Worksheets("COSTINGS")
    
    InptSht.Activate
    UsdRws = Range("C" & Rows.Count).End(xlUp).Row
    PcRws = WorksheetFunction.CountIf(Columns(3), "PC*")
    OhRws = WorksheetFunction.CountIf(Columns(3), "OH*")

    With CstSht
        .Rows(2).Font.ColorIndex = 3
        .Range("A2").Value = "PC"
        .Range("B2").Value = "Main Costs"
        .Range("C2").FormulaR1C1 = "=sum(r[1]c:r[" & PcRws & "]c)"
        .Range("D2").FormulaR1C1 = "=sum(r[1]c:r[" & PcRws & "]c)"
        .Range("E2").FormulaR1C1 = "=sum(r[1]c:r[" & PcRws & "]c)"
    End With
    
    Range("A:B,D:D").EntireColumn.Hidden = True
    Cells.AutoFilter Field:=3, Criteria1:="=PC*", Operator:=xlAnd
    Range("A2:H" & UsdRws).SpecialCells(xlCellTypeVisible).Copy CstSht.Range("A3")

    With CstSht
        .Rows(PcRws + 3).Font.ColorIndex = 3
        .Range("A" & PcRws + 3).Value = "OH"
        .Range("B" & PcRws + 3).Value = "Overheads"
        .Range("C" & PcRws + 3).FormulaR1C1 = "=sum(r[1]c:r[" & OhRws & "]c)"
        .Range("D" & PcRws + 3).FormulaR1C1 = "=sum(r[1]c:r[" & OhRws & "]c)"
        .Range("E" & PcRws + 3).FormulaR1C1 = "=sum(r[1]c:r[" & OhRws & "]c)"
    End With

    Cells.AutoFilter Field:=3, Criteria1:="=OH*", Operator:=xlAnd
    Range("A2:H" & UsdRws).SpecialCells(xlCellTypeVisible).Copy CstSht.Range("A" & 4 + PcRws)
    Range("A:B,D:D").EntireColumn.Hidden = False
    Cells.AutoFilter

Application.ScreenUpdating = True

End Sub
 
Upvote 0
What line did it fail on?
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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