+ Reply to Thread
Results 1 to 3 of 3

Function not working when used in userform

Hybrid View

  1. #1
    Registered User
    Join Date
    07-20-2019
    Location
    West Virginia
    MS-Off Ver
    2013
    Posts
    4

    Function not working when used in userform

    So to start, I'm super new at this and barely know what I'm doing. I'm trying to make a tracking sheet for logs that I get delivered to my sawmill. Ideally one of my employees can enter in the log characteristics in the userform and it will be transferred to a table to be tallied. I set up some if statements to choose a price based on species and grade. It works as intended when entered into a cell, however I was having trouble figuring out how to select the next row without the row being empty, so I had to remove the if statements and try to put them into the userform. When entered, I get a compile error for end of statement.

    Any tips on how to fix this or generally set it up better?

    Private Sub cbNext_Click()
    'Find Empty Row
    Dim rw As Integer
    Dim ws As Worksheet
    
    Set ws = Worksheets("Table")
    
    rw = ws.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row + 1
    
    'Submit log data
    ws.Cells(rw, 1).Value = Me.SpeciesList.Value
    ws.Cells(rw, 2).Value = Me.tbLength.Value
    ws.Cells(rw, 3).Value = Me.tbDiameter.Value
    ws.Cells(rw, 4).Value = Me.tbSweep.Value
    ws.Cells(rw, 5).Value = Me.tbCrook.Value
    ws.Cells(rw, 6).Value = Me.LogGrades.Value
    ws.Cells(rw, 7).Value = "=(((Table!C6-4)^2)*Table!B6)/16"
    ws.Cells(rw, 8).Value = "=IF(F6="Tie",IF(A6="White Oak",Master!$B$5,IF(A6="Red Oak",Master!$B$5,Master!$B$2)),IF(F6="Blocking",Master!$B$3,IF(F6="Pallet",Master!$B$4,"-")))"
    ws.Cells(rw, 9).Value = "=IF(H6=" - "," - ",H6*G6)"
    
    Unload Me
    Logs.Show
    
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    06-02-2012
    Location
    London, England
    MS-Off Ver
    365
    Posts
    397

    Re: Function not working when used in userform

    Hi, It's difficult to say if this would work without seeing a sample file, but try this slight rework of your code.
    Private Sub cbNext_Click()
        Dim rw As Integer
        Dim ws As Worksheet:        Set ws = Worksheets("Table")
        
        'Find Empty Row
        rw = ws.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row + 1
        
        'Submit log data
        With ws
            .Cells(rw, 1).Value = Me.SpeciesList.Value
            .Cells(rw, 2).Value = Me.tbLength.Value
            .Cells(rw, 3).Value = Me.tbDiameter.Value
            .Cells(rw, 4).Value = Me.tbSweep.Value
            .Cells(rw, 5).Value = Me.tbCrook.Value
            .Cells(rw, 6).Value = Me.LogGrades.Value
            .Cells(rw, 7).Formula = "=(((Table!C" & rw & "-4)^2)*Table!B" & rw & ")/16"
            .Cells(rw, 8).Formula = "=IF(F" & rw & "=""Tie"",IF(A" & rw & "=""White Oak"",Master!$B$5,IF(A" & rw & "=""Red Oak"",Master!$B$5,Master!$B$2)),IF(F" & rw & "=""Blocking"",Master!$B$3,IF(F" & rw & "=""Pallet"",Master!$B$4,""-"")))"
            .Cells(rw, 9).Formula = "=IF(H" & rw & "=""-"",""-"",H" & rw & "*G" & rw & ")"
        End With
        
        Unload Me
        Logs.Show
    End Sub
    B.

  3. #3
    Registered User
    Join Date
    07-20-2019
    Location
    West Virginia
    MS-Off Ver
    2013
    Posts
    4

    Re: Function not working when used in userform

    That worked perfectly, thank you.

+ 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. [SOLVED] Userform is not working.
    By jhakans in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-24-2019, 08:00 AM
  2. [SOLVED] progress bar userform inside userform not working
    By kevinu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-22-2018, 05:41 PM
  3. Why Isn't My Userform Working?
    By drsadistic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-27-2014, 11:18 PM
  4. [SOLVED] Gradually Fade Userform Into View [Userform Fade Out Working Already]
    By nadstradamus in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-05-2013, 04:12 AM
  5. [SOLVED] Sum function not working on time values from userform
    By lsteinbach in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-05-2013, 07:45 PM
  6. Userform Search Function Autofilter Results and Repopulate Userform
    By cindy71 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-16-2012, 03:46 PM
  7. Working with Cells on Userform
    By Jeff Ingraham in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-20-2006, 01:15 PM

Tags for this Thread

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