Compile error Variable not defind message advice

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,899
Office Version
  1. 2007
Platform
  1. Windows
Code shown below but not sure what it means / how to fix it
Line causing issue is shown in Red

Rich (BB code):
Private Sub CheckConnectorsUsed_Click()
  Dim r As Range, f As Range, Cell As String, added As Boolean
  Dim sh As Worksheet
  Set sh = Sheets("MCLIST")
  sh.Select
  With ListBox1
    .Clear
    .ColumnCount = 4
    .ColumnWidths = "130;130;130;130"
    
    Set r = Range("C8", Range("C" & Rows.Count).End(xlUp))
    Set f = r.Find(TextBox1.Value, LookIn:=xlValues, LookAt:=xlPart)
    If Not f Is Nothing Then
      Cell = f.Address
      Do
        added = False
        For i = 0 To .ListCount - 1
          Select Case StrComp(.List(i), f.Value, vbTextCompare)
            Case 0, 1
              .AddItem f.Value, i
              .List(i, 1) = f.Offset(, 1).Value
              .List(i, 2) = f.Offset(, 6).Value
              .List(i, 3) = f.Offset(, 9).Value
              .List(i, 4) = f.Row
              added = True
              Exit For
          End Select
        Next
        If added = False Then
          .AddItem f.Value
          .List(.ListCount - 1, 1) = f.Offset(, 1).Value
          .List(.ListCount - 1, 2) = f.Offset(, 6).Value
          .List(.ListCount - 1, 3) = f.Offset(, 9).Value
          .List(.ListCount - 1, 4) = f.Row
        End If
        Set f = r.FindNext(f)
      Loop While Not f Is Nothing And f.Address <> Cell
      .TopIndex = 0
      Else
    End If
  End With
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You haven't declared i as a variable. Add:

Code:
Dim i as Long

to the top of your routine.
 
Upvote 0
Solution

Forum statistics

Threads
1,226,538
Messages
6,191,636
Members
453,668
Latest member
Stephen_Santos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top