Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default find blanks crashes on error

I have a piece of code that doesn't respond to error handling:

On Error GoTo question_end

secondblank = Range("a" & firstqunw & ":a100").Find(What:="",
LookAt:=xlWhole).Row

It finds the second blank space in a column. When the column is empty it
fails (as I would expect) but then instead of error handling it crashes
with:

run-time error 91 object variable or With block variable not set

Any help or suggestions gratefully received

tp

full code is

If ActiveSheet.UsedRange.Count < 2 Then
MsgBox "There are no results available yet for that sheet"
Else

Dim firstblank As String
Dim firstqunw As String
Dim secondblank As String
Dim firstqwei As String

On Error GoTo question_error

firstblank = Columns("a:a").Find(What:="", LookAt:=xlWhole).Row
firstqunw = firstblank + 2
Cells.FindNext(After:=ActiveCell).Activate

On Error GoTo question_end

secondblank = Range("a" & firstqunw & ":a100").Find(What:="",
LookAt:=xlWhole).Row
Cells.FindNext(After:=ActiveCell).Activate
firstqwei = secondblank + 1


End If



  #2   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel
external usenet poster
 
Posts: 11,501
Default find blanks crashes on error

Hi,

The snippet you provide can't be the full code because it simply wouldn't
complile like that so you couldn't get a runtime error, can we see more of
the code

Mike


"teepee" wrote:

I have a piece of code that doesn't respond to error handling:

On Error GoTo question_end

secondblank = Range("a" & firstqunw & ":a100").Find(What:="",
LookAt:=xlWhole).Row

It finds the second blank space in a column. When the column is empty it
fails (as I would expect) but then instead of error handling it crashes
with:

run-time error 91 object variable or With block variable not set

Any help or suggestions gratefully received

tp

full code is

If ActiveSheet.UsedRange.Count < 2 Then
MsgBox "There are no results available yet for that sheet"
Else

Dim firstblank As String
Dim firstqunw As String
Dim secondblank As String
Dim firstqwei As String

On Error GoTo question_error

firstblank = Columns("a:a").Find(What:="", LookAt:=xlWhole).Row
firstqunw = firstblank + 2
Cells.FindNext(After:=ActiveCell).Activate

On Error GoTo question_end

secondblank = Range("a" & firstqunw & ":a100").Find(What:="",
LookAt:=xlWhole).Row
Cells.FindNext(After:=ActiveCell).Activate
firstqwei = secondblank + 1


End If




  #3   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel
external usenet poster
 
Posts: 107
Default find blanks crashes on error


"Mike H" wrote in message
...
Hi,

The snippet you provide can't be the full code because it simply wouldn't
complile like that so you couldn't get a runtime error, can we see more of
the code

Mike


The rest of the macro is very very long and really wouldn't help you as it
doen't reference this section


  #4   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default find blanks crashes on error

Maybe it's something in the error handling routine that you didn't share.

Personally, I'd use something like:

dim FirstBlankCell as range
set firstblankcell _
= Range("a" & firstqunw & ":a100").Find(What:="", LookAt:=xlWhole)
'and I'd specify all the parms to the .find

if firstblankcell is nothing then
'not found
firstblank = 0 '???
else
firstblank = firstblankcell.row
end if


teepee wrote:

I have a piece of code that doesn't respond to error handling:

On Error GoTo question_end

secondblank = Range("a" & firstqunw & ":a100").Find(What:="",
LookAt:=xlWhole).Row

It finds the second blank space in a column. When the column is empty it
fails (as I would expect) but then instead of error handling it crashes
with:

run-time error 91 object variable or With block variable not set

Any help or suggestions gratefully received

tp

full code is

If ActiveSheet.UsedRange.Count < 2 Then
MsgBox "There are no results available yet for that sheet"
Else

Dim firstblank As String
Dim firstqunw As String
Dim secondblank As String
Dim firstqwei As String

On Error GoTo question_error

firstblank = Columns("a:a").Find(What:="", LookAt:=xlWhole).Row
firstqunw = firstblank + 2
Cells.FindNext(After:=ActiveCell).Activate

On Error GoTo question_end

secondblank = Range("a" & firstqunw & ":a100").Find(What:="",
LookAt:=xlWhole).Row
Cells.FindNext(After:=ActiveCell).Activate
firstqwei = secondblank + 1

End If


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc
external usenet poster
 
Posts: 107
Default find blanks crashes on error


"Dave Peterson" wrote Personally, I'd use
something like:

dim FirstBlankCell as range
set firstblankcell _
= Range("a" & firstqunw & ":a100").Find(What:="", LookAt:=xlWhole)
'and I'd specify all the parms to the .find

if firstblankcell is nothing then
'not found
firstblank = 0 '???
else
firstblank = firstblankcell.row
end if


Many thanks Dave. That was a most effective solution. I'm in your debt as
ever.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel crashes on "Close" Visual Basic error 400 [email protected] Excel Discussion (Misc queries) 3 March 19th 08 03:45 PM
copy range of cells with blanks then paste without blanks justaguyfromky Excel Worksheet Functions 1 September 3rd 06 07:56 PM
help with this error-Compile error: cant find project or library JackR Excel Discussion (Misc queries) 2 June 10th 06 09:09 PM
replace "#DIV/0!" error with blanks Mark B Excel Worksheet Functions 0 June 22nd 05 10:19 AM
Paste Special Skip Blanks not skipping blanks, but overwriting... gsrosin Excel Discussion (Misc queries) 0 February 22nd 05 03:33 AM


All times are GMT +1. The time now is 09:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"