Oh Great & Powerful Mr Excel Gurus, please bestow your knowledge upon me, a humble desk jockey!
I have been tasked with creating a macro that will autopopulate a column in excel based on the values of two other columns (a store number (first column in example) and a date (second column in example)). The columns will be sorted by number (ascending) and then by date (oldest first). The third column will be populated with numbers 1,2 or 3.
The first time a store number appears along with the first date it appears with - it will be assigned a 1 in the third column. All instances of that store number/date combination will be assigned a 1 as well. If a second date appears with that store, it will be assigned a 2. If a third date appears with that store, it will be assigned a 3. If a fourth date appears with that store, it will be assigned a 1 - fifth date, 2 - sixth date, 3 etc etc looping 1-3 based on the date change for a particular store.
When the store number changes, the cycle repeats with the number/date combinations: 1,2,3,1,2,3 until a number has been assigned to all cells in the third column.
Example:
[TABLE="width: 50"]
<tbody>[TR]
[TD]10[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]12/15[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]12/15[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]22[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]22[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]31[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]31[/TD]
[TD]12/15[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]31[/TD]
[TD]12/20[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]31[/TD]
[TD]12/20[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]31[/TD]
[TD]12/25[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]44[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]44[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]44[/TD]
[TD]12/15[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]44[/TD]
[TD]12/20[/TD]
[TD]3[/TD]
[/TR]
</tbody>[/TABLE]
I don't have much experience coding, but I suspect that a Loop with an If statement could be used to accomplish this. I haven't the slightest idea of where to start - could you all help me out?
Cheers!
I have been tasked with creating a macro that will autopopulate a column in excel based on the values of two other columns (a store number (first column in example) and a date (second column in example)). The columns will be sorted by number (ascending) and then by date (oldest first). The third column will be populated with numbers 1,2 or 3.
The first time a store number appears along with the first date it appears with - it will be assigned a 1 in the third column. All instances of that store number/date combination will be assigned a 1 as well. If a second date appears with that store, it will be assigned a 2. If a third date appears with that store, it will be assigned a 3. If a fourth date appears with that store, it will be assigned a 1 - fifth date, 2 - sixth date, 3 etc etc looping 1-3 based on the date change for a particular store.
When the store number changes, the cycle repeats with the number/date combinations: 1,2,3,1,2,3 until a number has been assigned to all cells in the third column.
Example:
[TABLE="width: 50"]
<tbody>[TR]
[TD]10[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]12/15[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]12/15[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]22[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]22[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]31[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]31[/TD]
[TD]12/15[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]31[/TD]
[TD]12/20[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]31[/TD]
[TD]12/20[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]31[/TD]
[TD]12/25[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]44[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]44[/TD]
[TD]12/1[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]44[/TD]
[TD]12/15[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]44[/TD]
[TD]12/20[/TD]
[TD]3[/TD]
[/TR]
</tbody>[/TABLE]
I don't have much experience coding, but I suspect that a Loop with an If statement could be used to accomplish this. I haven't the slightest idea of where to start - could you all help me out?
Cheers!