Increment using last row and first cell

cainey1991

New Member
Joined
Feb 20, 2014
Messages
31
Hi all,

I am looking for a simple function. I have managed to break it down into small chunks but not getting anywhere with it.

When the macro is run it looks at a table and increments the ID when it adds a row.
IDname
D-1
Bill
D-2Ben

<tbody>
</tbody>

I can add the row but cant increment the ID. I am trying to break it down :
1. Look at last value in the last row and first cell - cannot work out
2. Increment this value by 1

Any help would be great.

D
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,313
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
MAybe this



Excel 2010
AB
1IDname
2D-1Bill
3D-2Ben
4D -3
5D -4
Sheet1
Cell Formulas
RangeFormula
A4="D -" & RIGHT(A3,1)+1
A5="D -" & RIGHT(A4,1)+1
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,313
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
Better



Excel 2010
AB
1IDname
2D-1Bill
3D-2Ben
4D -3
5D -4
6D -5
Sheet1
Cell Formulas
RangeFormula
A4="D -"& ABS(MID(A3,FIND("-",A3,1),99))+1
A5="D -"& ABS(MID(A4,FIND("-",A4,1),99))+1
A6="D -"& ABS(MID(A5,FIND("-",A5,1),99))+1
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,313
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
It can be applied to VBA
Try
Code:
Private Sub worksheet_change(ByVal target As Range)
lr = Cells(Rows.Count, "B").End(xlUp).Row
If target.Count > 1 Then Exit Sub
If Intersect(target, Range("B2:B" & lr)) Is Nothing Then Exit Sub
x = 1
For r = 2 To lr
    Range("A" & r).Value = "D- " & x
    x = x + 1
Next r
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,025
Messages
5,856,912
Members
431,837
Latest member
megantang

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
Top