Results 1 to 2 of 2

Coding script error-cmd button to open form and for to add new entry to list

Threaded View

  1. #1
    Registered User
    Join Date
    04-27-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2003
    Posts
    33

    Coding script error-cmd button to open form and for to add new entry to list

    Hi All,

    I'm working with Excel 97 and have an error in my VB code. I have a sheet (Admin) which contains a button to open a form which is used to add a new entry to a list on another sheet (PriceSchedule). When I try to run the button to open the form, I get an error "Runtime error 9: sub script out of range" or "Runtime error 1004" depending on if I use a ! after the sheet name.

    When I run the code for the form (Add_New_Price), the new data to not written to the last row of the PriceSchedule sheet.

    Sub Add_New_Price_Button_Click()
    Range("B3").Value = Sheets("PriceSchedule!").Range("A20000").End(x1Up).Row
    Range("c1").Value = Format(Date, "MM/dd/yy")
    Range("d1").Value = ""
    Range("e1").Value = ""
    Range("f1").Value = ""
    Range("g1").Value = Format(Number, "0.00")
    Private Sub Add_Price_Button_Click()
    Dim NewRow As Integer
    NewRow = Worksheets("Admin").Range("b3").Value + 1
    
    If Len(Add_New_Price.P_Species.Value) = 0 Then
    MsgBox "The Date field can not be left empty!", vbOKOnly, "MeadInKent"
    Add_New_Price.P_Species.SetFocus
    
    Exit Sub
    End If
    
    Worksheets("PriceSchedule").Cells(NewRow, 1).Value = DateValue(Add_New_Price.P_Date.Value)
    Worksheets("PriceSchedule").Cells(NewRow, 2).Value = Add_New_Price.P_Species.Value
    Worksheets("PriceSchedule").Cells(NewRow, 3).Value = Add_New_Price.P_Grade.Value
    Worksheets("PriceSchedule").Cells(NewRow, 4).Value = Add_New_Price.P_Mkt.Value
    Worksheets("PriceSchedule").Cells(NewRow, 5).Value = Add_New_Price.P_Price.Value
    
    Add_New_Price.Hide
    End Sub

    Add_New_Price.Show
    Add_New_Price.P_Species.SetFocus
    End Sub

    Also is it posible to use a dropdown list on the form to choose the values "species, grade and market" from validated lists that woulld be the new values that are appended to the new row at the end of the PriceSchedule sheet? If so, how would this be accomplished?

    Help in debugging this code would be great appreciated.

    Thanks much!
    Attached Files Attached Files

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