#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 355
Default Macro Fails

Hello

I have a monthly report that has 31 rows of data for each day. The
following code is used to display only the current day. The first cell in
Column AG for each day contains the date and the other cells for that day in
col AG are blank. The code works except for the the 31st of the months that
have 31 days. The code is failing on
Rows(rng.Row & ":" & rng.Row + 30).Hidden = False and it appears as though
the code is trying to hide all rows of the sheet.

Does anyone see what may be causing this, and how do I fix it?

Private Sub CommandButton1_Click()
Dim FindString As Date
Dim rng As Range

Application.ScreenUpdating = False
FindString = Date
Columns("AG:AG").Select
Selection.EntireColumn.Hidden = False
Rows(3 & ":" & Rows.Count).Hidden = False

With Sheets("MySheet").Range("AG:AG")
Set rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then

Rows(3 & ":" & Rows.Count).Hidden = True
Rows(rng.Row & ":" & rng.Row + 30).Hidden = False
Application.Goto rng, True
Else
MsgBox "Date Not Found"
End If
End With
Columns("AG:AG").Select
Selection.EntireColumn.Hidden = True
Application.ScreenUpdating = True
Range("C1").Select
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 342
Default Macro Fails

The problem is that you are trying to unhide rows that are not in the used
range of the worksheet. That is, the last row you are hoping to unhide has
no data anywhere in the row and Excel doesn't know it exists. If you put a
value in a cell below the 31st item on the 31st day you macro will run just
fine.

Tom

"Sandy" wrote:

Hello

I have a monthly report that has 31 rows of data for each day. The
following code is used to display only the current day. The first cell in
Column AG for each day contains the date and the other cells for that day in
col AG are blank. The code works except for the the 31st of the months that
have 31 days. The code is failing on
Rows(rng.Row & ":" & rng.Row + 30).Hidden = False and it appears as though
the code is trying to hide all rows of the sheet.

Does anyone see what may be causing this, and how do I fix it?

Private Sub CommandButton1_Click()
Dim FindString As Date
Dim rng As Range

Application.ScreenUpdating = False
FindString = Date
Columns("AG:AG").Select
Selection.EntireColumn.Hidden = False
Rows(3 & ":" & Rows.Count).Hidden = False

With Sheets("MySheet").Range("AG:AG")
Set rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then

Rows(3 & ":" & Rows.Count).Hidden = True
Rows(rng.Row & ":" & rng.Row + 30).Hidden = False
Application.Goto rng, True
Else
MsgBox "Date Not Found"
End If
End With
Columns("AG:AG").Select
Selection.EntireColumn.Hidden = True
Application.ScreenUpdating = True
Range("C1").Select
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 355
Default Macro Fails

Thank you!!

"TomPl" wrote:

The problem is that you are trying to unhide rows that are not in the used
range of the worksheet. That is, the last row you are hoping to unhide has
no data anywhere in the row and Excel doesn't know it exists. If you put a
value in a cell below the 31st item on the 31st day you macro will run just
fine.

Tom

"Sandy" wrote:

Hello

I have a monthly report that has 31 rows of data for each day. The
following code is used to display only the current day. The first cell in
Column AG for each day contains the date and the other cells for that day in
col AG are blank. The code works except for the the 31st of the months that
have 31 days. The code is failing on
Rows(rng.Row & ":" & rng.Row + 30).Hidden = False and it appears as though
the code is trying to hide all rows of the sheet.

Does anyone see what may be causing this, and how do I fix it?

Private Sub CommandButton1_Click()
Dim FindString As Date
Dim rng As Range

Application.ScreenUpdating = False
FindString = Date
Columns("AG:AG").Select
Selection.EntireColumn.Hidden = False
Rows(3 & ":" & Rows.Count).Hidden = False

With Sheets("MySheet").Range("AG:AG")
Set rng = .Find(What:=FindString, _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not rng Is Nothing Then

Rows(3 & ":" & Rows.Count).Hidden = True
Rows(rng.Row & ":" & rng.Row + 30).Hidden = False
Application.Goto rng, True
Else
MsgBox "Date Not Found"
End If
End With
Columns("AG:AG").Select
Selection.EntireColumn.Hidden = True
Application.ScreenUpdating = True
Range("C1").Select
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
Macro fails in different WB Dave Birley Excel Programming 3 April 26th 07 04:40 PM
Macro fails in network Tom H[_2_] Excel Programming 1 May 25th 06 05:23 PM
Macro Suddenly Fails Bill Martin Excel Discussion (Misc queries) 2 September 16th 05 01:55 PM
Macro Fails to Run Correctly JK Excel Programming 3 August 20th 04 09:40 PM
Macro fails without VB help files Michael Miazga[_2_] Excel Programming 0 July 22nd 03 04:10 PM


All times are GMT +1. The time now is 12:14 AM.

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"