Simple Macro to Copy/Paste Cells onto Another Sheet

k3yn0t3

New Member
Joined
Oct 5, 2023
Messages
42
Office Version
  1. 365
Platform
  1. Windows
Hi everyone, Can anyone give me a hand with a macro that will run and copy the results generated on one sheet onto another sheet as values? xl2bb sheets below to illustrate if helpful

I need it to...
  1. Enter a “1” into cell D108 on “OnOff” sheet
  2. Refresh entire workbook
  3. Copy and paste *as values* the results on “Summary” sheet cells C8:P18 onto “Output tab”
    1. The destination cell on “output” tab—where I need to paste C8—should be one cell to the left right of the Scenario # input into OnOff cell D108
  4. Repeat the above, but enter “2” into D108
  5. Repeat, but enter “3” into D108
Thank you very much in advance.

Regards,
Sam

"OnOff" Sheet
Factories_v65.xlsx
CDEFGHIJKLMNOPQRSTU
108Scenario Chooser2
109Include in Total On / Off Switch1
110Factory 1Factory 2Factory 3Factory 4Factory 5Factory 6Factory 7Factory 8Factory 9Factory 10Factory 11Factory 12Factory 13Factory 14Factory 15Factory 16Factory 17Factory 18
111Scenario 1111111111111111111
112Scenario 2000101111111101111
113Scenario 3111101000000001111
OnOff
Cell Formulas
RangeFormula
D109D109=+OFFSET(D109,$D$108,)


"Summary" Sheet
Cell Formulas
RangeFormula
I8:P8I8=+H8+1
I9:P9I9=+H9+10000
I11:P11I11=+H11+50000
H12,H14:P14H12=+-100000
I12:P12I12=+H12-10000
H13:P13H13=+H12+H11
H15:H16,I16:P16H15=+-20000
I15:P15I15=+H15-200
H17:P17H17=+SUM(H13:H16)


"Output" Tab
Factories_v65.xlsx
ABCDEFGHIJKL
21-2016-2017-2018-2019-2020-2021-2022-2023-2024
3Products Manufactured#################################################################################
4
5Revenue(500,000)(550,000)(600,000)(650,000)(700,000)(750,000)(800,000)(850,000)(900,000)
6Cost of Goods Sold100,000110,000120,000130,000140,000150,000160,000170,000180,000
7Gross Profit(400,000)(440,000)(480,000)(520,000)(560,000)(600,000)(640,000)(680,000)(720,000)
8OpEx100,000100,000100,000100,000100,000100,000100,000100,000100,000
9Overhead20,00020,20020,40020,60020,80021,00021,20021,40021,600
10Rent, Utilities20,00020,00020,00020,00020,00020,00020,00020,00020,000
11EBITDA(260,000)(299,800)(339,600)(379,400)(419,200)(459,000)(498,800)(538,600)(578,400)
12
13
142-2016-2017-2018-2019-2020-2021-2022-2023-2024
15Products Manufactured#################################################################################
16
17Revenue(500,000)(550,000)(600,000)(650,000)(700,000)(750,000)(800,000)(850,000)(900,000)
18Cost of Goods Sold100,000110,000120,000130,000140,000150,000160,000170,000180,000
19Gross Profit(400,000)(440,000)(480,000)(520,000)(560,000)(600,000)(640,000)(680,000)(720,000)
20OpEx100,000100,000100,000100,000100,000100,000100,000100,000100,000
21Overhead20,00020,20020,40020,60020,80021,00021,20021,40021,600
22Rent, Utilities20,00020,00020,00020,00020,00020,00020,00020,00020,000
23EBITDA(260,000)(299,800)(339,600)(379,400)(419,200)(459,000)(498,800)(538,600)(578,400)
24
253-2016-2017-2018-2019-2020-2021-2022-2023-2024
26Products Manufactured#################################################################################
27
28Revenue(500,000)(550,000)(600,000)(650,000)(700,000)(750,000)(800,000)(850,000)(900,000)
29Cost of Goods Sold100,000110,000120,000130,000140,000150,000160,000170,000180,000
30Gross Profit(400,000)(440,000)(480,000)(520,000)(560,000)(600,000)(640,000)(680,000)(720,000)
31OpEx100,000100,000100,000100,000100,000100,000100,000100,000100,000
32Overhead20,00020,20020,40020,60020,80021,00021,20021,40021,600
33Rent, Utilities20,00020,00020,00020,00020,00020,00020,00020,00020,000
34EBITDA(260,000)(299,800)(339,600)(379,400)(419,200)(459,000)(498,800)(538,600)(578,400)
Output
Cell Formulas
RangeFormula
A14A14=+A2+1
A25A25=+A14+1
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Please try the following on a copy of your workbook. Just watch the destination rows.
VBA Code:
Option Explicit
Sub Simple_Copy()
    Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
    Set ws1 = Worksheets("OnOff")
    Set ws2 = Worksheets("Summary")
    Set ws3 = Worksheets("Output")
    Dim rngSrc As Range, rngNum As Range, i As Long, n As Long
    Set rngSrc = ws2.Range("C8:P18")
    Set rngNum = ws1.Range("D108")
    Dim a(): a = Array(1, 2, 3)
    Dim b(): b = Array(2, 14, 25)       '<-- *** Check these destination row numbers ***
    
    For i = LBound(a) To UBound(a)
        rngNum.Value = a(i)
        ws2.Calculate
        rngSrc.Copy ws3.Cells(b(n), 2)
        n = n + 1
    Next i
End Sub
 
Upvote 0
Sorry, just noticed your requirement to paste values...
VBA Code:
Option Explicit
Sub Simple_Copy()
    Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
    Set ws1 = Worksheets("OnOff")
    Set ws2 = Worksheets("Summary")
    Set ws3 = Worksheets("Output")
    Dim rngSrc As Range, rngNum As Range, i As Long, n As Long
    Set rngSrc = ws2.Range("C8:P18")
    Set rngNum = ws1.Range("D108")
    Dim a(): a = Array(1, 2, 3)
    Dim b(): b = Array(2, 14, 25)       '<-- *** Check these destination row numbers ***
    
    For i = LBound(a) To UBound(a)
        rngNum.Value = a(i)
        ws2.Calculate
        rngSrc.Copy
        ws3.Cells(b(n), 2).PasteSpecial xlPasteValues
        Application.CutCopyMode = False
        n = n + 1
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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