Macro to copy and paste cells based on the result in a single cell

saraapple

Board Regular
Joined
Feb 3, 2020
Messages
165
Office Version
  1. 2010
Platform
  1. Windows
I have a worksheet with 10 small pivot tables that show data depending on the input (the more data the more tables will be populated).
I have a formula to calculate how many tables will be in use and I know which cells I could need to copy depending on that........how do I feed this information into a macro to make the correct copy selection?

NEW WAVE FILE TRUNKS.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAM
1LDLOAD 120:00:00LDLOAD 222:24:00LDLOAD 300:48:00LDLOAD 403:12:00LDLOAD 505:36:00LDLOAD 608:00:00LDLOAD 710:24:00LD(blank) LD(blank) LD(blank) NUMBER OF LOADS7
2PRIORITY(Multiple Items)PRIORITY(Multiple Items)PRIORITY(Multiple Items)PRIORITY(Multiple Items)PRIORITY(Multiple Items)PRIORITY(Multiple Items)PRIORITY(Multiple Items)PRIORITY(Multiple Items)PRIORITY(Multiple Items)PRIORITY(Multiple Items)
3
4PRIORITYSum of PltsRow LabelsSum of PltsRow LabelsSum of PltsRow LabelsSum of PltsRow LabelsSum of PltsRow LabelsSum of PltsRow LabelsSum of PltsRow LabelsSum of PltsRow LabelsSum of PltsRow LabelsSum of Plts
5Truro6Inverness6Ilkeston5Cheltenham5Cannock2Bromborough4Redditch4Grand TotalGrand TotalGrand Total
6Plymouth10Perth5Burton6Gloucester8Stafford5St Helens10Walsall4
7Torquay6Livingston5Barrow In Furness5Lincoln7Crewe7Liverpool6Telford10
8Exeter7Falkirk6Blackburn5Chester6Fenton4Trafford13Shrewsbury7
9Barnstaple6Clydebank New4Bristol Cribbs Causeway6Altrincham4Newcastle Under Lyme8Stockport9Grand Total25
10Taunton7Kilmarnock6Hereford8Kidderminster4Chesterfield New4Redditch3
11Yeovil3Uddingston8Worcester9Wolverhampton6Bangor7Grand Total45
12Grand Total45Mansfield5Cheltenham1Cannock5Bromborough8
13Grand Total45Grand Total45Grand Total45Grand Total45
14
15
16
17
18
19
20
21
Trunks
Cell Formulas
RangeFormula
C1C1=IF($B$1="Load 1",('Timings Stk1'!$F$4),(""))
G1G1=IF($F$1="Load 2",('Timings Stk1'!$F$5),(""))
K1K1=IF($J$1="Load 3",('Timings Stk1'!$F$6),(""))
O1O1=IF($N$1="Load 4",('Timings Stk1'!$F$7),(""))
S1S1=IF($R$1="Load 5",('Timings Stk1'!$F$8),(""))
W1W1=IF($V$1="Load 6",('Timings Stk1'!$F$9),(""))
AA1AA1=IF($Z$1="Load 7",('Timings Stk1'!$F$10),(""))
AE1AE1=IF($Z$1="Load 8",('Timings Stk1'!$F$11),(""))
AH1AH1=IF($Z$1="Load 9",('Timings Stk1'!$F$12),(""))
AK1AK1=IF($Z$1="Load 10",('Timings Stk1'!$F$13),(""))
AM1AM1=SUM(IF(FREQUENCY(IF(LEN('Result 1'!D3:D1006)>0,MATCH('Result 1'!D3:D1006,'Result 1'!D3:D1006,0),""),IF(LEN('Result 1'!D3:D1006)>0,MATCH('Result 1'!D3:D1006,'Result 1'!D3:D1006,0),""))>0,1))
Press CTRL+SHIFT+ENTER to enter array formulas.


My data is above and the copy scenarios are here:
NEW WAVE FILE TRUNKS.xlsm
JKL
1LoadsCells to copy
21A1B20
32A1F20
43A1J20
54A1N20
65A1R20
76A1V20
87A1Z20
98A1AD20
109A1AH20
1110A1AL20
Timings Stk1


I would normally try and record a macro but have no idea how to select cells based on a condition.
Any support would be greatly appreciated.
Thanks for taking the time
Sara
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hey Sara,
You might consider the following...

VBA Code:
Sub ConditionalCopy()
Dim Col As Long
For Col = 2 To 36 Step 4
    If ActiveSheet.Cells(1, Col) <> "" Then Cells(20, Col) = Range("A1")
Next Col
End Sub

The code examines cells B1, F1, J1 through AJ1, and if not blank, fills the corresponding cell in row 20 with A1.
Cheers,
Tony
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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