+ Reply to Thread
Results 1 to 4 of 4

Compile error: variable not defined

Hybrid View

  1. #1
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    8

    Compile error: variable not defined

    New to VBA and just trying to make some edits to some existing code. I have basically copied a pre-existing form and module and changed names from "Appendix" to "Drawing" as I am trying to replicate what the piece of code already produces for a table of appendices, for my drawings. However, when I try and run the form I get Compile error: Variable not defined with lstDrawings highlighted.

    Private Sub UserForm_Initialize()
    
    Dim iNextDrawID  As Integer
    Dim sNextDrawLet As String
    Dim iChar       As Integer
    Dim iDraw        As Integer
    Dim sLet        As String
    Dim sDesc       As String
    Dim bBlankAfter As Boolean
    
    iNextDrawID = 1
    On Error Resume Next
    iNextDrawID = ActiveDocument.CustomDocumentProperties("NextDrawingID").Value
    On Error GoTo 0
    
    sNextDrawLet = "A"
    On Error Resume Next
    sNextDrawLet = ActiveDocument.CustomDocumentProperties("NextDrawing").Value
    On Error GoTo 0
    
    If sNextDrawLet <> "A" Then
    
        For iChar = Asc("A") To Asc(sNextDrawLet) - 1
    
            For iDraw = 1 To iNextDrawID - 1
    
                sLet = ""
                On Error Resume Next
                sLet = ActiveDocument.CustomDocumentProperties("Drawing" & Format(iDraw, "00") & "_Let").Value
                On Error GoTo 0
    
                If sLet = Chr(iChar) Then
    
                    sDesc = ""
                    bBlankAfter = False
                    On Error Resume Next
                    sDesc = ActiveDocument.CustomDocumentProperties("Drawing" & Format(iDraw, "00") & "_Desc").Value
                    bBlankAfter = CBool(ActiveDocument.CustomDocumentProperties("Drawing" & Format(iDraw, "00") & "_BlankPage").Value)
                    On Error GoTo 0
    
    
                    With lstDrawings
                        .AddItem sLet
                        .Column(1, .ListCount - 1) = sDesc
                        If bBlankAfter Then
                            .Column(2, .ListCount - 1) = "Yes"
                        Else
                            .Column(2, .ListCount - 1) = "No"
                        End If
                        .Column(4, .ListCount - 1) = iDraw
                    End With
    
    
    
    
    
                    Exit For
    
                End If
    
            Next
    
        Next
    
    End If
    
    End Sub
    Is this something that should be defined in my global module which I am missing?

    Any help is much appreciated.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Compile error: variable not defined

    What is lstDrawings?
    Last edited by AB33; 08-12-2014 at 03:50 AM.

  3. #3
    Registered User
    Join Date
    05-09-2014
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Compile error: variable not defined

    iNextDraw is already defined as an Integer. It is the following section of code which is returning the compile error:

    With lstDrawings
                            .AddItem sLet
                            .Column(1, .ListCount - 1) = sDesc
                            If bBlankAfter Then
                                .Column(2, .ListCount - 1) = "Yes"
                            Else
                                .Column(2, .ListCount - 1) = "No"
                            End If
                            .Column(4, .ListCount - 1) = iApp
                        End With

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Compile error: variable not defined

    You need to define 1stDrawings

    Dim 1stDrawings as something

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Compile error Variable not defined...?
    By swade730 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-21-2013, 01:59 AM
  2. Compile error: Variable not defined
    By Francisco Sousa in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-17-2013, 04:02 PM
  3. Compile error variable not defined
    By AsifShabbir in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-04-2011, 10:53 AM
  4. Compile Error Variable not Defined
    By Mooseman60 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-16-2010, 10:13 AM
  5. Compile error, variable not defined
    By davegb in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-19-2005, 12:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1