I would have done it differently but add an on error
And, do you really want to do this with each calculation??. I don’t think so...

'On Error Resume Next
For Each c In rng

Don Guillett
Microsoft MVP Excel
SalesAid Software
dguille...@gmail.com

From: cardak 
Sent: Wednesday, June 13, 2012 2:20 PM
To: excel-macros@googlegroups.com 
Subject: $$Excel-Macros$$ vba - run time error 9 out of range

hi all,

im new to VBA and trying run below, when i run the code excel throws run time 9 
error message, can you please help on this error

Thanks

Private Sub Worksheet_Calculate()
Dim rng As Range, c As Range
Dim ws As Worksheet
Dim lastRow As Long
Dim x As Variant

Set ws = Worksheets("Component List")
lastRow = ws.Cells(ws.Cells.Rows.Count, 1).End(xlUp).Row
Set rng = ws.Range("A5:A" & lastRow)


For Each c In rng
For i = 1 To Sheets.Count
If c.Offset(0, 1).Value = "Yes" And Trim(c.Value) = Sheets(i).Name Then
Sheets(Trim(c.Value)).Visible = xlSheetVisible
Else
Sheets(Trim(c.Value)).Visible = xlSheetHidden
End If
Next i
Next c
End Sub -- 
FORUM RULES (986+ members already BANNED for violation)
 
1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
 
2) Don't post a question in the thread of another member.
 
3) Don't post questions regarding breaking or bypassing any security measure.
 
4) Acknowledge the responses you receive, good or bad.
 
5) Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 
 
NOTE : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.
 
------------------------------------------------------------------------------------------------------
To post to this group, send email to excel-macros@googlegroups.com
 
To unsubscribe, send a blank email to excel-macros+unsubscr...@googlegroups.com

-- 
FORUM RULES (986+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.

------------------------------------------------------------------------------------------------------
To post to this group, send email to excel-macros@googlegroups.com

To unsubscribe, send a blank email to excel-macros+unsubscr...@googlegroups.com

Reply via email to