Restarting Sequential Numbers

MHamid

Active Member
Joined
Jan 31, 2013
Messages
472
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I need to add sequential numbers in column AX based on the change invalues in column BC.
Column BC is already sorted so all like values are together.
The data in column AX starts at cell AX5.

Is it possible to create a vba code that will add sequential numbersbased on the changes in column BC?
The values in columns BC will always be “Up” and “Down”. For instance,
Column AX (row 5) Column BC
1 Up
2 Up
3 Up
1 Down
2 Down
3 Down

Thank you

 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
How about just a formula?

A​
B​
C​
1​
2​
Up
1​
B2: =1 + (A2=A1)*N(B1)
3​
Up
2​
4​
Up
3​
5​
Down
1​
6​
Down
2​
7​
Down
3​
8​
Up
1​
9​
Up
2​
10​
Down
1​
 
Upvote 0
I am automating a process and this is one piece that needs to beincluded with the automation.
I do have the following formula in vba code, but it’s not workingproperly. It worked the first time and now it’s not working.
It is adding the formula in cell AX513 and I am not sure why sincethere is no data that far down. The end of the data in row AY is currently 6rows of data (will change monthly). Also the copying and pasting as values

Rich (BB code):
Rich (BB code):
Rich (BB code):
Rich (BB code):
'Add Sequential Numbers
    Dim lastRow1 As Long
    lastRow1 = Cells(Rows.Count,"AY").End(xlUp).Row
 
    Range("AX5" &lastRow1).formula = "=IF(BC6=BC5,AX5+1,1)"
    Range("AX:AX").Copy
   Range("AX:AX").PasteSpecial Paste:=xlPasteFormulas,Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode =False 


This code will only give me a count of the first cell only, but itleaves it at 0. I need this formula copied to the last row of data. Just theformula only not the cell formatting.

Rich (BB code):
Rich (BB code):
Rich (BB code):
Rich (BB code):
'Add Sequential Numbers
   Range("AX5").formula = "=IF(BC6=BC5,AX5+1,1)"
    Range("AX:AX").Copy
   Range("AX:AX").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode =False


What am I doing wrong?

Thank you

 
Upvote 0
Hello,

I just figured it out. My formula was off.

Rich (BB code):
Rich (BB code):
Rich (BB code):
Rich (BB code):
'Add Sequential Numbers
    Range("AX5:AX"& lastRow1).formula = "=IF(BC5=BC4,AX4+1,1)"
    Range("AX:AX").Copy
   Range("AX:AX").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode =False


Thank you
 
Upvote 0

Forum statistics

Threads
1,214,540
Messages
6,120,107
Members
448,945
Latest member
Vmanchoppy

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