VBA code for cycling down through rows and update column based on fixed cell values

Sixaside

New Member
Joined
Apr 13, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hi, I'm sure this is simple but I haven't been able to modify any VBA code I've found to do what I want. Hopefully someone can help.

What I need to do is copy the values in A2:C2 to G2:I2, and then copy the value of M2(value, not the formula) to D2. Then I want to move onto copying A3:C3 to G2:I2 and then copy the value of M2 to D3. So basically cycle down through columns A:C until there is no more data in those columns and each time copy the values of the new row to G2:I2 and copy E2 to column D for the row in question. Columns E and G:I will only ever be populated in row 2 at any time. Screenshot included. Any help much appreciated.

1618353336229.png
 
Correction: in the textbox in the image H2:R2 should read H2:J2 and H3:R3 should read H3:J3.
 
Upvote 0

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
I was going to upload but can't see an option to do that
No, we don't have workbook uploads in this forum, but we do have XL2BB

I also suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Thanks for the tip. Minisheet below. Hope someone can help. The cell references in my opening post can be ignored. Details of what I want to do as follows:

I want to copy the value of L2 (not the formula) to D2 after firstly copying the values of A2:C2 to P2:R2. Then I want to copy the values in AC:C3 to P2:R2 and then copy the new value of L2 to D3 and then repeat for each row where there is data in columns A to C.
Some context:
P4 to R6 is a matrix based on values in P2:R2.
P9:R11 is the inverse of the matrix.
H2:J2 is the MMULT of E2:G2 and the matrix inverse.
H3:J3 is the MMULT of E3:G3 and the same matrix inverse. Et. etc.
When the values in P2:R2 change, all the values in H:J change and thus the value in L2 changes. It is this value I want to paste in the appropriate row in column D



Workbook1.xlsx
ABCDEFGHIJKLMNOPQR
1ABCEFGHIJL123
26.344.571.6310-1001080384293256.344.571.63
33.283.442.5220-1001015361276
41.356.3510.0740-1009493382601-0.631.001.00
52.283.603.6150-10088431524321.00-3.571.00
64.023.812.0870-10081929222731.001.00-5.34
71.943.824.6080-100753270210
85.294.581.71100-100688247194
93.443.282.52110-100623224177-43.5549-15.2667-11.0175
101.604.476.93130-100557201161-15.2667-5.64644-3.91709
111.704.126.09140-100492178144-11.0175-3.91709-2.98459
121.385.8410.10160-100427155128
131.634.785.86170-100361132111
143.193.512.53190-10029610995
152.763.293.05200-1002318678
163.293.822.34220-1001656362
171.704.235.83230-1001004145
182.873.292.93250-100351829
196.874.581.60300-100-205-66-32
205.053.991.84350-100-423-143-87
213.963.432.23400-100-640-219-142
229.565.051.45450-100-858-295-197
233.383.482.44500-100-1076-372-252
242.863.502.79550-100-1294-448-308
251.544.777.43600-100-1512-524-363
261.356.3510.07650-100-1729-601-418
273.803.702.18700-100-1947-677-473
283.073.442.65750-100-2165-753-528
291.545.036.90800-100-2383-830-583
301.485.018.45850-100-2600-906-638
311.833.985.11900-100-2818-982-693
327.985.591.46950-100-3036-1059-748
332.543.383.291000-100-3254-1135-803
341.704.435.55
351.824.035.05
361.664.246.36
371.584.227.92
381.964.024.25
3910.565.811.38
Sheet1
Cell Formulas
RangeFormula
H2:J33H2=MMULT(E2:G2,P$9:R$11)
L2L2=MAXIFS(E:E,H:H,">0")
P4:R6P4=IF(P$1=$N4,(SMALL($P$2:$R$2,$N4)-1)*-1,1)
P9:R11P9=MINVERSE(P4:R6)
Press CTRL+SHIFT+ENTER to enter array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
N14:S21Cell Value=0textNO
N14:S21Cell Value<0textNO
N14:S21Cell Value>0textNO
 
Upvote 0
Sorry, I have been away for a couple of weeks so have not been able to respond. Thanks for updating your profile and for the XL2BB sample.

If you still need help with this, give this code a try with a copy of your workbook.

VBA Code:
Sub CycleRows()
  Dim rw As Range

  For Each rw In Range("A2", Range("C" & Rows.Count).End(xlUp)).Rows
    Range("P2:R2").Value = rw.Value
    Range("D" & Rows.Count).End(xlUp).Offset(1).Value = Range("L2").Value
  Next rw
End Sub

It produced these results for me:

Sixaside.xlsm
ABCD
1ABC
26.344.571.6325
33.283.442.5270
41.356.3510.0713
52.283.603.6160
64.023.812.0850
71.943.824.6040
85.294.581.7130
93.443.282.5270
101.604.476.9322
111.704.126.0925
121.385.8410.1013
131.634.785.8625
143.193.512.5370
152.763.293.0580
163.293.822.3460
171.704.235.8325
182.873.292.9385
196.874.581.6022
205.053.991.8435
213.963.432.2355
229.565.051.4514
233.383.482.4465
242.863.502.7975
251.544.777.4320
261.356.3510.0713
273.803.702.1855
283.073.442.6575
291.545.036.9022
301.485.018.4517
311.833.985.1135
327.985.591.4617
332.543.383.2970
341.704.435.5530
351.824.035.0535
361.664.246.3625
371.584.227.9219
381.964.024.2545
3910.565.811.3813
Sheet3
 
Upvote 0

Forum statistics

Threads
1,214,967
Messages
6,122,503
Members
449,090
Latest member
RandomExceller01

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