Finding Last Empty Cell In A Dynamic Range

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,562
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I'm struggling with a relatively easy function in vba. I am trying to find the row number based on the first empty cell in a dynamic range (rng_cntb)
Here is what I have that isn't providing the right answer:

Code:
Set rng_cntb = ws_master.Range("A13:A" & mstr_lr_pdr)
ws_master.Unprotect
x = rng_cntb.SpecialCells(xlCellTypeLastCell).Row
msgbox "Next available empty row in the available range is: " & x

In my testing, mstr_lr_pdr = 36, so therefore rng_cntb = ws_master.range("A13:A36")
The last cell in that range is at A21.
I am expecting a value for x of 22, but I'm getting 77.

Can someone correct my code, or suggest an alternate. I know how to find the last row in an entire worksheet, but not within a defined range.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Maybe the below if you mean the next empty cell after the last cell with data

VBA Code:
Set rng_cntb = ws_master.Range("A13:A" & mstr_lr_pdr)
ws_master.Unprotect
x = rng_cntb.Find("*", , xlValues, , xlByRows, xlPrevious).Row + 1
MsgBox "Next available empty row in the available range is: " & x
 
Upvote 0
Solution
Thank you Mark! That did the trick.
 
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,720
Members
448,294
Latest member
jmjmjmjmjmjm

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