VBA code help

jamie.gill

New Member
Joined
Jan 28, 2011
Messages
30
I am creating a customer database in excell that identifies customers on a plan via a reference number.
A plan has a reference number and on the spreadsheet and all customers on a plan are input next to each other on a spreadsheet at the same time.

E.g
[TABLE="width: 331"]
<tbody>[TR]
[TD]Plan number[/TD]
[TD]customer number[/TD]
[/TR]
[TR]
[TD="align: right"]4[/TD]
[TD="align: right"]21689[/TD]
[/TR]
[TR]
[TD="align: right"]23[/TD]
[TD="align: right"]54863[/TD]
[/TR]
[TR]
[TD="align: right"]9[/TD]
[TD="align: right"]35489[/TD]
[/TR]
[TR]
[TD="align: right"]32[/TD]
[TD="align: right"]36547[/TD]
[/TR]
[TR]
[TD="align: right"]32[/TD]
[TD="align: right"]25418[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD="align: right"]12458[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]36985[/TD]
[/TR]
[TR]
[TD="align: right"]7[/TD]
[TD="align: right"]32154[/TD]
[/TR]
[TR]
[TD="align: right"]7[/TD]
[TD="align: right"]32546[/TD]
[/TR]
[TR]
[TD="align: right"]98[/TD]
[TD="align: right"]22144[/TD]
[/TR]
[TR]
[TD="align: right"]10[/TD]
[TD="align: right"]25222[/TD]
[/TR]
[TR]
[TD="align: right"]56[/TD]
[TD="align: right"]36887[/TD]
[/TR]
[TR]
[TD="align: right"]24[/TD]
[TD="align: right"]23569[/TD]
[/TR]
</tbody>[/TABLE]
To group these by back ground i entered a formula into a cell on the far right of the data range with the formula =IF(B2=B1,E1,MOD(E1+1,2)) so if this returns 1 that row turns blue by conditional format. This also ensures all plans block color as if the plan code doesn't change the color wont.

however if i insert a row to add a new customer to a plan this code doesn't copy... is there a macro i can make which takes this formula and copies it all the way down the range of the data (but not beyond)... i.e. it analyzes how much data is in the spread sheet and only copies it to that length.

Thanks :)
 
If you set your data up as a table, then your formulas will autofill when you add a new row (tables are dynamic, so Excel always knows how big they are).

HTH
 
Upvote 0

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