Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: get an error if i press calculate-1 button without entries in the 4 Labels in Red

  1. #1
    Senior Member
    Join Date
    Jul 2013
    Posts
    102
    Rep Power
    12

    get an error if i press calculate-1 button without entries in the 4 Labels in Red

    How do i change code in the userform so that i must have entries in the following Textboxs which are Red in colour on the Userform....i get an error if i hit the Calculate-1 button without entries in these 4 textbox`s
    System Feed Flow
    Feed Concentration
    Outlet Concentration
    CT Feed Flow

    Also how do i make the results show as whole numbers?

    Also can the colour of the numbers in the result box`s be Blue?

    Still new to VBA code so i have i made this coding correct...it does work though

    Best Regards

    Jeff
    Attached Files Attached Files

  2. #2
    Junior Member
    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0
    Hi Jeff still new to VBA myself but I think this should work at the end of your command button code

    If UserForm1.TextBox7.Value = "" Then
    MsgBox "Please enter a System Flow Rate"
    Exit sub
    End If

    also use this example to change the font colour

    Me.TextBox7.ForeColor = vbBlue

    hope this helps

  3. #3
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    13
    Put following code at start of commandbutton-code
    Code:
        For Each it In Array(7, 8, 9, 17)
            If Me("Textbox" & it) = vbNullString Then MsgBox "Missing value": Exit Sub
        Next
    Coloring textboxtext will only work if enabled. They are now greyed out because of disabling them.

  4. #4
    Senior Member
    Join Date
    Jul 2013
    Posts
    102
    Rep Power
    12
    Thanks for help

    When all entries are in the userform i then want this transferred to Result Sheet...the code i used gives error...where have i gone wrong please

    When i transfer the 1st data to column D , the next entries into column E through to column I

    Jeff
    Attached Files Attached Files

  5. #5
    Senior Member
    Join Date
    Jul 2013
    Posts
    102
    Rep Power
    12
    I made a couple of changes but still get error

    I tried by changing Rows to column in code but still error

    Regards

    Jeff
    Attached Files Attached Files

  6. #6
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    13
    Code:
    Private Sub CommandButton5_Click()
        
        With Sheets("RESULTS")
            myarray = Array(TextBox7.Value, TextBox8.Value, TextBox9.Value, , TextBox4.Text, TextBox5.Text, , _
                TextBox6.Text, TextBox1.Text, , TextBox2.Text, TextBox3.Text, , TextBox10.Text, TextBox11.Text, , _
                TextBox12.Text, TextBox13.Text, TextBox14.Text, TextBox15.Text, TextBox16.Text, , _
                TextBox17.Value, TextBox18.Text, TextBox19.Text, TextBox20.Text, TextBox21.Text)
            mycol = .Cells(6, .Columns.Count).End(xlToLeft).Offset(, 1).Column
            For i = 0 To UBound(myarray)
                .Cells(i + 6, mycol) = myarray(i)
            Next
        End With
        
       MsgBox "Data Transferred"
       
    End Sub

  7. #7
    Senior Member
    Join Date
    Jul 2013
    Posts
    102
    Rep Power
    12
    Thank you
    I keep getting a zero number for Textbox5....tried changing the formula but always get a zero?
    In the userform i get some numbers with a decimal point...can all answers be a whole number?

    Cheers

  8. #8
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    13
    Check the order of Textbox-calculation in your Calculate-code.
    Check F1 for rounding numbers( Round, Roundup, Rounddown)

  9. #9
    Senior Member
    Join Date
    Jul 2013
    Posts
    102
    Rep Power
    12
    I must be missing something here as i have tried many combinations to get a value in Solids in Concentration (userform Textbox5)....the values are visible in all textboxs on Userform except for the value in Textbox5
    Jeff

  10. #10
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    13
    jeff,

    To calculate TB5 you need the value of TB1 too, but TB1 is still empty at that time because you only calculate it's value two steps further in your code.

Similar Threads

  1. adding entries into combobox with code
    By paul_pearson in forum Excel Help
    Replies: 1
    Last Post: 07-23-2013, 01:01 PM
  2. Macro To Calculate Percentage Allocation
    By Howardc in forum Excel Help
    Replies: 3
    Last Post: 06-01-2013, 01:59 PM
  3. Replies: 2
    Last Post: 05-26-2013, 03:41 PM
  4. Red Green Amber Three Color Conditional Format
    By paul_pearson in forum Excel Help
    Replies: 1
    Last Post: 03-07-2013, 06:50 PM
  5. Calculate the Hours
    By leopaulc in forum Excel Help
    Replies: 2
    Last Post: 02-27-2013, 02:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •