Reading data directly from a spreadsheet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • almaroc
    New Member
    • Nov 2011
    • 48

    Reading data directly from a spreadsheet

    I am trying to read the data directly from an Excel file into a text box. i keep getting this error OBJECT REQUIRED
    here is my code:
    Code:
    Private Sub CboMS_AfterUpdate()
     With worksheets = ("C:\todays\Small Pricing.xls")
       
        If Me.CboMS.ListIndex <> -1 Then
        
              'MsgBox ("[" & Me.CboMonth & "]")
              MsgBox ("[" & .range("D16").Value & "]")
                Select Case Me.CboMS.ListIndex
                    Case 0
                    Select Case Me.CboZS.ListIndex
           
                       Case 0
                            Me.txt_6MS = .range("D15").Value
                       Case 1
                            Me.txt_6MS = .range("D16").Value
                        Case 2
                            Me.txt_6MS = .range("D17").Value
                        Case 3
                            Me.txt_6MS = .range("D18").Value
                        Case 4
                           Me.txt_6MS = .range("D19").Value
                   End Select
                   'i have some code in here different 
                End Select
    End If
    End With
    End Sub
    the error is on line 6 but basically it's every line that has .range in it.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32663

    #2
    You should never post a question with code without first considering the points in When Posting (VBA or SQL) Code.

    Your first line is not proper code and wouldn't compile. Of course none of the rest of it will work. Please check the basics before posting more questions.

    Comment

    • almaroc
      New Member
      • Nov 2011
      • 48

      #3
      Sorry about that. I have edited the post and the code is now complete

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32663

        #4
        I don't know how to respond to that.

        Line #2 is still nonsense and the code will clearly not compile due at least to this (if not other problems too). You need to follow the instructions in the linked article and compile the code first. It won't compile as line #2 isn't recognisable code. I can't think how I can make the point any clearer.

        Comment

        Working...