VBA - increment base number, lookup new values and copy them to table

aba264

New Member
Joined
Feb 6, 2014
Messages
3
Hi,

I have a table with 9 columns and 2 row(including one header), where the data(a,b,c) changes based on a number(x). a,b, c are lookups/formulas based on a larger table.
I need to record the changes made when I increment that number(x). I tried to map it in the table below.

I have never used VBA. If anyone could give me some guidance, it would be great.

Thanks,

Amir

initial tableh1h2h3
xabc
VBA generated result tableh1h2h3
xabc
x+1a1b1c1
x+2a2b2c2
x+nanbncn

<tbody>
</tbody>
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
if you want to keep your records right below as in your example and your data goes from A1:I2 then

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    If Target.Address <> "$A$2" Then Exit Sub
    Application.EnableEvents = False
    Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Resize(, 9) = Range("A2:I2").Value
    Application.EnableEvents = True
End Sub
 
Upvote 0
Awesome!!
One more question, how would you provide an increment, a range and automate it, so it populates for all values in the range?
 
Upvote 0
So, I have a long list of numbers (x) which I need to increment.
Can I set the initial number(x) , an increment value (+1) and a limit (limit = 50). Then run the macro and have it automatically generate the 50 lines?
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,772
Members
449,049
Latest member
greyangel23

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