FINDING THE LAST VALUE IN COL D WITH BLANK ROWS BETWEEN VALUES

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
917
Office Version
  1. 365
Platform
  1. Windows
As described in the title.
This code does not work even if col D is specified as below. Cols A, B and C all have non-blank rows down to row 47.
Code:
With Sheets("BIBLESTUDYALL")
    lastRow = .Cells(.rows.count, "D").End(xlUp).Row
End With
MsgBox  lastRow
MsgBox always keeps giving 47 as LastRow - the last used row in cols A, B and C. Not what I want. The value should be 10.
as image below shows

What am I not seeing? - this couldn't be simpler.

Please help if you can.

Thank as always,
cr
 

Attachments

  • FIND THE LAST VALUE IN COLUM D WITH BLANK ROWS.  IN THIS CASE 10. .png
    FIND THE LAST VALUE IN COLUM D WITH BLANK ROWS. IN THIS CASE 10. .png
    3.8 KB · Views: 28

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Are there formulas in the cells returning ""
Edit: my bad you are looking for the value in the cell, see post 3 by dsfobral
 
Upvote 0
didn't you defined lastrow as the number of the row?

shouldn't you use
lastRow = .Cells(.rows.count, "D").End(xlUp).Value

or simply
lastRow = .Cells(.rows.count, "D").End(xlUp)
 
Upvote 0
didn't you defined lastrow as the number of the row?

shouldn't you use
lastRow = .Cells(.rows.count, "D").End(xlUp).Value

or simply
lastRow = .Cells(.rows.count, "D").End(xlUp)

Are there formulas in the cells returning ""
Edit: my bad you are looking for the value in the cell, see post 3 by dsfobral
Hi MARK,
Didn't know if you are still following the thread, so I copied you also on my reply:
....
I copied your first line of code above as below and just inserted between the With End With block.
I gives a 'Type Mismatch error at this line. Her's the revised code block with your code line substituted:
Code:
Private Sub cmdFINDBKMARK_Click()
Dim LastRow As Long
With Sheets("BIBLESTUDYALL")
  LastRow = .Cells(.rows.count, "D").End(xlUp).Value  ---> 'Type Mismatch error here
End With
MsgBox LastRow
End Sub
To me this is beyond easy - but it's got me stumped.
Thx , cr
 
Upvote 0
I ran it with the data below and got no type mismatch
1716945356015.png

Are you sure that the cells below the cell with 10 in it are actually blank cells i.e. no formulas / characters (including spaces) in the cells
 
Upvote 0
I ran it with the data below and got no type mismatch
View attachment 112022
Are you sure that the cells below the cell with 10 in it are actually blank cells i.e. no formulas / characters (including spaces) in the cells
Hi MARK,
Didn't know if you are still following the thread, so I copied you also on my reply:
....
I copied your first line of code above as below and just inserted between the With End With block.
I gives a 'Type Mismatch error at this line. Her's the revised code block with your code line substituted:
Code:
Private Sub cmdFINDBKMARK_Click()
Dim LastRow As Long
With Sheets("BIBLESTUDYALL")
  LastRow = .Cells(.rows.count, "D").End(xlUp).Value  ---> 'Type Mismatch error here
End With
MsgBox LastRow
End Sub
To me this is beyond easy - but it's got me stumped.
Thx , cr
 
Upvote 0
didn't you defined lastrow as the number of the row?

shouldn't you use
lastRow = .Cells(.rows.count, "D").End(xlUp).Value

or simply
lastRow = .Cells(.rows.count, "D").End(xlUp)
I used Clearcontents on the entire column, inserted numbers on random rows with blank cells between
values, reran the code twice and it gave me the correct last value both times. I must have unknowingly had data or formulas
in the cells below the last value in the column. Thanks for all your help.

cr
 
Upvote 0
Happy we could help

If it was formulas returning "" below the cell with 10 in it causing the issue (the cells in between are irrelevant) then you could use the code below (btw I didn't post the previous code, dsfobral did)

VBA Code:
Private Sub cmdFINDBKMARK_Click()
    Dim LastRow As Long
    With Sheets("BIBLESTUDYALL")
        LastRow = .Columns(4).Find("*", , xlValues, , xlByRows, xlPrevious) 
    End With
    MsgBox LastRow
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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