• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 781
  • Last Modified:

VBA Excel 2010 - First blank cell in a column

Dear Experts,

I would like to know which is the row number of the first blank cell in column A, could you please advise how it should be in VBA?

thanks,
0
csehz
Asked:
csehz
  • 6
  • 3
  • 3
  • +2
1 Solution
 
Rory ArchibaldCommented:
Something like:
range("A:A").Find(what:="", lookat:=xlwhole).Row

Open in new window

0
 
Rob HensonIT & Database AssistantCommented:
Depends what you mean by "first blank cell".

Do you mean the bottom of existing data? This would be ignoring rows between blocks of data/calculations inserted for appearance.

This will take the cursor to the bottom right of Used Range and then down 1 and then cone back to column A.

ActiveCell.SpecialCells(xlLastCell).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.End(xlToLeft).Select

Open in new window


Thanks
Rob H
0
 
csehzAuthor Commented:
Rprya thanks, trying your solution I got an error message

Compile error: Invalid use of property

And in the code window the .row is marked
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
StephenJRCommented:
This perhaps?
MsgBox Columns(1).SpecialCells(xlCellTypeBlanks)(1).Row

Open in new window

0
 
csehzAuthor Commented:
Rob, yes the final target would be to determine with this the last used row, and I also have a method of this but it is doing the same like your code on the attached picture.

It is a tricky file which I am not sure how works technically and your code also jumped under of the last EoF. But you can see the up of it there are a lot of "blank" cell, I mean probably for the Excel it is not blank but for me yes
Last-row.jpg
0
 
csehzAuthor Commented:
Stephen thanks your code gaves result 789 so not 4980, and this 789 is my target so seems working
0
 
Rob HensonIT & Database AssistantCommented:
Try this:

ActiveCell.SpecialCells(xlLastCell).Select
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.End(xlToLeft).Select
ActiveCell.Offset(-1, 0).Range("A1").Select
If Activecell.Value = "EOF" Then 
Selection.End(xlUp).Select
Else
ActiveCell.Offset(1, 0).Range("A1").Select
End If

Open in new window


This goes to the bottom as before goes up one and checks the cell value, if it is "EOF" it then carries on up otherwise it goes back down one.

Thanks
Rob H
0
 
Rob HensonIT & Database AssistantCommented:
Alternatively without the hopping about:

ActiveCell.SpecialCells(xlLastCell).Select
R = ActiveCell.Row
Cells(R ,1).Select
If Activecell.Value = "EOF" Then Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select

Thanks
Rob H
0
 
kgerbChief EngineerCommented:
Unless I'm missing something, I'm pretty sure this can be done with a single line.  Maybe I'm not understanding the question fully.

Kyle
Cells(Rows.Count, 1).End(xlUp).Offset(1).Row

Open in new window

0
 
csehzAuthor Commented:
Rob thanks the efforts, but somehow both your codes jumped under the EOF line. Since then I got to know that those are from an imported text from menu Data/From Text. So maybe the Excel does not consider those EOF cells like value in the cell.

Kgerb, tried also your code but got an error message - Run-time error 438, Object does not support this property or method.

But seems having the solution from StephenJR this works even on this tricky file so will accept it

MsgBox Columns(1).SpecialCells(xlCellTypeBlanks)(1).Row

thanks,
0
 
kgerbChief EngineerCommented:
Ok, whatever, but I think for future reference you should understand how to find the last cell in a given column.  It's easy.  To do it manually, scroll down to the very last row in the worksheet 1048576.  Now hold ctrl down and push the up arrow.  It will take you up to the next cell with a value in it.  The same can be done in VBA with the syntax I provided.  If you would like it to be reported in a message box then use the following.  It will work with any workbook, "tricky" or not:).  good luck, happy coding:).

Kyle
Sub GetLastRowInColA()
MsgBox "Last row = " & Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
End Sub

Open in new window

0
 
csehzAuthor Commented:
Kyle thanks, but in this "tricky" file your code also brings 4980 :-) Like Rob's two codes, you can see on the attached picture at before comment that this is the first row under the EoF lines.

So far for me only StephenJR's code brought the 789 which is visually the true for a user.

In the practice I used to use such line for the target

ActiveSheet.UsedRange.row - 1 + ActiveSheet.UsedRange.Rows.Count

which worked so far always, except this file because also this brings 4980 :-)
0
 
kgerbChief EngineerCommented:
Ok, sounds good.  I just wanted you to be aware of the method.  Not good for every case but still very useful.  I use it constantly.  Good luck and take care.

Kyle
0
 
csehzAuthor Commented:
Kyle yes I also never thought that once this old reliable code for last row once will not work on a case, but seems can happen

thanks,
Zsolt
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now