#1   Report Post  
Posted to microsoft.public.excel.misc
nc nc is offline
external usenet poster
 
Posts: 119
Default Help with this macro

Please help with the following macro, sometimes it works but when it doesn't
I get the following error message "Runtime error '91 object variable or With
block variable not set". It stops on this row, rw1 = rng.Find(".", , ,
xlWhole).Row



Private Sub Worksheet_Activate()

Dim cell As Range
Application.ScreenUpdating = False
Cells.EntireRow.Hidden = False
Set rng = Sheets("income").Range("A9:A100")

rw1 = rng.Find(".", , , xlWhole).Row
rw2 = rng.Find("Funding Council grants", , , xlWhole).Row

Range(Cells(rw1, "A"), Cells(rw2 - 3, "A")).EntireRow.Hidden = True
Cells(1, "A").Select
Application.ScreenUpdating = True
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,726
Default Help with this macro

Sounds like the Find failed, Test for it

Private Sub Worksheet_Activate()
Dim rng As Range
Dim cell As Range
Dim rw1 As Long, rw2 As Long
Application.ScreenUpdating = False
Cells.EntireRow.Hidden = False
Set rng = Range("A9:A100")

On Error Resume Next
Set cell = rng.Find(".", , , xlWhole)
If cell Is Nothing Then
MsgBox "Dot not fopund"
Else
rw1 = cell.Row
Set cell = Nothing
Set cell = rng.Find("Funding Council grants", , , xlWhole)
If cell Is Nothing Then
MsgBox "Grants not found"
Else
rw2 = cell.Row
On Error GoTo 0
Range(Cells(rw1, "A"), Cells(rw2 - 3, "A")).EntireRow.Hidden = True
Cells(1, "A").Select
End If
End If
On Error GoTo 0
Application.ScreenUpdating = True
End Sub



--

HTH

Bob Phillips

(replace xxxx in the email address with gmail if mailing direct)

"nc" wrote in message
...
Please help with the following macro, sometimes it works but when it

doesn't
I get the following error message "Runtime error '91 object variable or

With
block variable not set". It stops on this row, rw1 = rng.Find(".", , ,
xlWhole).Row



Private Sub Worksheet_Activate()

Dim cell As Range
Application.ScreenUpdating = False
Cells.EntireRow.Hidden = False
Set rng = Sheets("income").Range("A9:A100")

rw1 = rng.Find(".", , , xlWhole).Row
rw2 = rng.Find("Funding Council grants", , , xlWhole).Row

Range(Cells(rw1, "A"), Cells(rw2 - 3, "A")).EntireRow.Hidden = True
Cells(1, "A").Select
Application.ScreenUpdating = True
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.misc
nc nc is offline
external usenet poster
 
Posts: 119
Default Help with this macro

Thanks for replying to my query. I managed to pin point the problem.

The following statement needs to be changed to

rw1 = rng.Find(".", , xlValues, xlWhole)

The range contains a function.


"nc" wrote:

Please help with the following macro, sometimes it works but when it doesn't
I get the following error message "Runtime error '91 object variable or With
block variable not set". It stops on this row, rw1 = rng.Find(".", , ,
xlWhole).Row



Private Sub Worksheet_Activate()

Dim cell As Range
Application.ScreenUpdating = False
Cells.EntireRow.Hidden = False
Set rng = Sheets("income").Range("A9:A100")

rw1 = rng.Find(".", , , xlWhole).Row
rw2 = rng.Find("Funding Council grants", , , xlWhole).Row

Range(Cells(rw1, "A"), Cells(rw2 - 3, "A")).EntireRow.Hidden = True
Cells(1, "A").Select
Application.ScreenUpdating = True
End Sub

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
error when running cut & paste macro Otto Moehrbach Excel Worksheet Functions 4 August 9th 06 01:49 PM
Compiling macro based on cell values simonsmith Excel Discussion (Misc queries) 1 May 16th 06 08:31 PM
Search, Copy, Paste Macro in Excel [email protected] Excel Worksheet Functions 0 January 3rd 06 06:51 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Highlight Range - wrong macro, please edit. Danny Excel Worksheet Functions 8 October 19th 05 11:11 PM


All times are GMT +1. The time now is 01:19 PM.

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

About Us

"It's about Microsoft Excel"