Finding Last Empty Cell In A Dynamic Range

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
3,895
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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,072
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
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
 
Solution

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
3,895
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Thank you Mark! That did the trick.
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,072
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
You're welcome
 

Watch MrExcel Video

Forum statistics

Threads
1,130,407
Messages
5,641,972
Members
417,249
Latest member
serrulate

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