Results 1 to 16 of 16

Why do I get an error when running the code for an UserForm from a standard module?

Threaded View

kjy1989 Why do I get an error when... 09-23-2013, 12:35 PM
TMS Re: why is this code... 09-23-2013, 12:44 PM
HaHoBe Re: why is this code... 09-23-2013, 12:51 PM
TMS Re: why is this code... 09-23-2013, 12:57 PM
HaHoBe Re: why is this code... 09-23-2013, 01:05 PM
kjy1989 Re: why is this code... 09-23-2013, 01:06 PM
TMS Re: why is this code... 09-23-2013, 01:16 PM
TMS Re: why is this code... 09-23-2013, 01:11 PM
kjy1989 Re: why is this code... 09-23-2013, 01:19 PM
kjy1989 Re: why is this code... 09-23-2013, 01:17 PM
TMS Re: why is this code... 09-23-2013, 01:24 PM
TMS Re: why is this code... 09-23-2013, 01:34 PM
kjy1989 Re: why is this code... 09-23-2013, 10:18 PM
TMS Re: why is this code... 09-24-2013, 01:00 AM
kjy1989 Re: Why do I get an error... 09-24-2013, 01:50 AM
TMS Re: Why do I get an error... 09-24-2013, 03:37 AM
  1. #1
    Forum Contributor
    Join Date
    12-03-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    107

    Why do I get an error when running the code for an UserForm from a standard module?

    hi, this code returns an error "variable not defined" and i don't know why.

    So i have this form that does all the macros in the ok button, here it is:

    
    Private Sub OkButton_Click()
    
        Application.ScreenUpdating = False
    
        Select Case ComboBox_LocalCost.ListIndex
            Case 0
                Set UnitCostColumn = Range("A:A")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 1
                Set UnitCostColumn = Range("B:B")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 2
                Set UnitCostColumn = Range("C:C")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 3
                Set UnitCostColumn = Range("D:D")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 4
                Set UnitCostColumn = Range("E:E")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 5
                Set UnitCostColumn = Range("F:F")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 6
                Set UnitCostColumn = Range("G:G")
                localcosttester.Caption = UnitCostColumn.Address
            Case 7
                Set UnitCostColumn = Range("H:H")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 8
                Set UnitCostColumn = Range("I:I")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 9
                Set UnitCostColumn = Range("J:J")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 10
                Set UnitCostColumn = Range("K:K")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 11
                Set UnitCostColumn = Range("L:L")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 12
                Set UnitCostColumn = Range("M:M")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 13
                Set UnitCostColumn = Range("N:N")
                localcosttester.Caption = UnitCostColumn.Address
            Case 14
                Set UnitCostColumn = Range("O:O")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 15
                Set UnitCostColumn = Range("P:P")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 16
                Set UnitCostColumn = Range("Q:Q")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 17
                Set UnitCostColumn = Range("R:R")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 18
                Set UnitCostColumn = Range("S:S")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 19
                Set UnitCostColumn = Range("T:T")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 20
                Set UnitCostColumn = Range("U:U")
                localcosttester.Caption = UnitCostColumn.Address
            Case 21
                Set UnitCostColumn = Range("V:V")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 22
                Set UnitCostColumn = Range("W:W")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 23
                Set UnitCostColumn = Range("X:X")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 24
                Set UnitCostColumn = Range("Y:Y")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 25
                Set UnitCostColumn = Range("Z:Z")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 26
                Set UnitCostColumn = Range("AA:AA")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 27
                Set UnitCostColumn = Range("AB:AB")
                localcosttester.Caption = UnitCostColumn.Address
            Case 28
                Set UnitCostColumn = Range("AC:AC")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 29
                Set UnitCostColumn = Range("AD:AD")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 30
                Set UnitCostColumn = Range("AE:AE")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 31
                Set UnitCostColumn = Range("AF:AF")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 32
                Set UnitCostColumn = Range("AG:AG")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 33
                Set UnitCostColumn = Range("AH:AH")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 34
                Set UnitCostColumn = Range("AI:AI")
                localcosttester.Caption = UnitCostColumn.Address
            Case 35
                Set UnitCostColumn = Range("AJ:AJ")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 36
                Set UnitCostColumn = Range("AK:AK")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 37
                Set UnitCostColumn = Range("AL:AL")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 38
                Set UnitCostColumn = Range("AM:AM")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 39
                Set UnitCostColumn = Range("AN:AN")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 40
                Set UnitCostColumn = Range("AO:AO")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 41
                Set UnitCostColumn = Range("AP:AP")
                localcosttester.Caption = UnitCostColumn.Address
            Case 42
                Set UnitCostColumn = Range("AQ:AQ")
                localcosttester.Caption = UnitCostColumn.Address
    
            Case 43
                Set UnitCostColumn = Range("AR:AR")
                localcosttester.Caption = UnitCostColumn.Address
    
    
        End Select
    
    'more code of the same procudres here...

    The code becomes too big and based on my research i should assign this code on a module and just put the Run "Macro_Name" in the OK button,
    but when i do it the combo boxes i have becomes unidentified variables, why is that so?
    Last edited by kjy1989; 09-24-2013 at 01:43 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. vba code returning Run Time Error 1004 method 'undo' of object
    By Ironman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-24-2012, 08:17 PM
  2. Working code on my machine is returning out of range error on another machine.
    By je.suis.ketan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-16-2012, 11:51 PM
  3. Excel 2007 : VBA Code returning error
    By jchessher in forum Excel General
    Replies: 3
    Last Post: 04-11-2011, 11:59 PM
  4. Code returning error 400
    By reggie1000 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-10-2009, 05:53 AM
  5. Replies: 4
    Last Post: 03-24-2006, 07:20 AM

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