Return Row Number Based on Last Empty Cell in Different Column/Specified Range?

soybomb10

New Member
Joined
Jul 19, 2017
Messages
3
BK3yn
U3nZmeu.png
BK3yn


Hello all,

Above is basically what my spreadsheet looks like but with a little more detail, but this is all I think I need to provide for a gist of what I am having a problem with.

Basically what I am trying to do is the following:
- For each ID number, search column C (status column) for the last cell with anything in it (within the range of the ID number, not the entire column) and return that row number
- Then return the step number of one row after the row found in previous step
- Repeat process for next ID number

Hopefully I've explained this well and this can be done through VBA...thanks for the help!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
To give an example of what the desired output/process would be with above image:

Macro would identify the range of cells in column C where column A is ID = 1
Then it would search column C within that range and return row = 4 because that is the last nonempty row/cell
Then it would go to column B, add one to the value found in previous step (so row 5 now), and return the step number in row 5 which is 4
 
Upvote 0
Hi.
See if this code could help you.
The "Step Number" founded will be on column 'D'.

Code:
Sub FindStep()
 Dim lngStatusRow As Long, k As Long, x As Long
  For k = 2 To Cells(Rows.Count, 1).End(3).Row
   x = Application.CountIf(Range("A2:A" & Cells(Rows.Count, 1).End(3).Row), Cells(k, 1))
    If Cells(k + x - 1, 3) <> "" Then
     lngStatusRow = k + x - 1
    Else: lngStatusRow = Cells(k + x - 1, 3).End(3).Row
    End If
    Cells(k + x - 1, 4) = Cells(lngStatusRow + 1, 2)
    k = k + x - 1
  Next k
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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