+ Reply to Thread
Results 1 to 3 of 3

Expected Function or Variable Error !!

Hybrid View

  1. #1
    Registered User
    Join Date
    01-20-2008
    Posts
    26

    Expected Function or Variable Error !!

    Hi,

    I'm designing a system in excel however all of a sudden my code has stopped working that i'm using with drop down boxes.

    The i'm using is as follows with slight variations as to what is copied depending on which drop down box it's assigned to....I have no idea why this is suddenly happening to all of the drop down box code!


    Public Sub Time()
    
    
    ID = Cells(3, 9)
    
    If ID = 1 Then
    Cells(4, 13).Select
    Cells(4, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    If ID = 2 Then
    Cells(5, 13).Select
    Cells(5, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    If ID = 3 Then
    Cells(6, 13).Select
    Cells(6, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    If ID = 4 Then
    Cells(7, 13).Select
    Cells(7, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    If ID = 5 Then
    Cells(8, 13).Select
    Cells(8, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    If ID = 6 Then
    Cells(9, 13).Select
    Cells(9, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    If ID = 7 Then
    Cells(10, 13).Select
    Cells(10, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    If ID = 8 Then
    Cells(11, 13).Select
    Cells(11, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    
    If ID = 9 Then
    Cells(12, 13).Select
    Cells(12, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    
    If ID = 10 Then
    Cells(13, 13).Select
    Cells(13, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    
    If ID = 11 Then
    Cells(14, 13).Select
    Cells(14, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    
    If ID = 12 Then
    Cells(15, 13).Select
    Cells(15, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    
    If ID = 13 Then
    Cells(16, 13).Select
    Cells(16, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    If ID = 14 Then
    Cells(17, 13).Select
    Cells(17, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    If ID = 15 Then
    Cells(18, 13).Select
    Cells(18, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    
    If ID = 16 Then
    Cells(19, 13).Select
    Cells(19, 13).copy
    Cells(23, 3).Select
    ActiveSheet.Paste
    
    End If
    End Sub
    Last edited by VBA Noob; 03-02-2008 at 06:29 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    I would change the name to not conflict with the VBA Time statement, and then shorten it as shown.
    Public Sub MyTime()
        Dim ID As Long
        ID = Cells(3, 9).Value
        If ID >= 1 And ID <= 16 Then
            Cells(ID + 3, 13).Copy Destination:=Cells(23, 3)
        End If
    End Sub
    VBA Noob edited your post to change the quote tags to code tags. Would you please use them in the future for code?
    Last edited by shg; 03-02-2008 at 07:27 PM.

  3. #3
    Registered User
    Join Date
    01-20-2008
    Posts
    26
    Thanks, that worked.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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