There are a lot of possibilities and without knowing what line of code is
throwing the error it is difficult to be certain.

The most likely errors are that either a sheet-name is not exactly the same
as the trimmed name in Column A (for example the sheet name might have a
space at the end) or the sheet   "Component List"  is not called exactly
that.

I suspect there is a problem with your logic anyhow.  It might be worth
posting a trimmed down version of the workbook (Four sheets only, and
remove any superfluous data and particularly anything confidential) Include
the macros in the workbook.  We could then have a look at it and make
suggestions.

As Don says, it is really not appropriate to run a macro with a hefty
amount of work to do, every time the worksheet is calculated.  It might be
better to just look for changes in Columns A and B as nothing else seems
likely to affect the outcome.

Why do you need to look through each sheet to see if its name is the same
as c.value?  Why not just use

For each c in rng
If c.offset(0,1)=Yes then
Worksheets(c.value).visible=true
else
Worksheets(c.value).visible=false
end if
Next c

<Warning - Aircode not tested>

Why not run through the names in Col A and Trim them in place - once and
forget about doing it subsequently?

If the sheet names have trailing spaces and that is causing the problems,
either fix them (ws.name = trim(ws.name) in a macro or or make the list in
A match the sheet names.

The logic in your macro does not work anyhow.  When c reaches the last
value at the bottom of column A it will set that sheet visible and all the
other sheets hidden (including the Component List)

HTH

Regards
David

On 14 June 2012 05:20, cardak <gez...@gmail.com> wrote:

> 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




-- 
David Grugeon

-- 
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