PDA

View Full Version : Runs OK on my PC but not on another



CaptRon
01-04-2008, 01:32 PM
This code is associated with a userform (FrmOAINav) and runs fine on my PC but on 2 other office machines it locks up Excel. Opening VBE then executing the code indicates that it is simply running.........and running......and running.....

Would someone please take a look at this code to see what I may have done wrong that would cause this?

Thanks, Ron

Private Sub ListBox1_Click()
On Error GoTo ErrorHandler
Dim i As Integer, sht As String
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
sht = ListBox1.List(i)
End If
Next i
Sheets(sht).Activate
ErrorHandler:
End Sub

Private Sub UserForm_Initialize()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Outcome" And ws.Name <> "Efficiency" And ws.Name <> "Explanatory" And ws.Name <> "Output" Then
ListBox1.AddItem (ws.Name)
End If
Next ws
End Sub

Private Sub CommandButton2_Click()
Unload Me
End Sub

Bob Phillips
01-04-2008, 02:17 PM
Nothing looks obvious Ron, but assuming it is not a mult-select listbox, try



Private Sub ListBox1_Click()
Sheets(ListBox1.Value).Activate
End Sub

CaptRon
01-04-2008, 04:54 PM
Your much more abbreviated code works just as well for me. I'll have to wait til Monday to see if it works OK on the office mgr's PC as she is gone for the w/e.

Thanks. Ron