+ Reply to Thread
Results 1 to 3 of 3

If Statements in Userform TextBox to populate other textbox

Hybrid View

  1. #1
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    If Statements in Userform TextBox to populate other textbox

    Hi All

    With the below CommandButton1_Click Macro, What I want to do is the following: Incorporate this code to make my If Statement work.

    If (Me.Box10.Value > 0 Then
    ws.Range("F18") = Me.Box12.Value * 4
    ws.Range("F17") = Me.Box13.Value * 4
    Else
    ws.Range("F18") = Me.Box12.Value 
    ws.Range("F17") = Me.Box13.Value 
    End If

    Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Dim ws As Worksheet
    
    If CBox.Value = "" Then
    MsgBox "  PLEASE ENTER A WEEK NO"
    Exit Sub
    End If
    If CBox1.Value = "" Then
    MsgBox "     PLEASE SELECT A EMPLOYEE"
    Exit Sub
    End If
    If Not Evaluate("ISREF('" & CBox1.Value & "'!A1)") Then
        MsgBox "  GENERATE PAYSLIP"
        Exit Sub
    End If
    
    Set ws = Sheets(CBox1.Value)
    ws.Activate
    
    ws.Range("E5") = CBox.Value
    ws.Range("E6") = Me.Box.Value & " " & Me.Box1.Value & " " & Me.Box2.Value
    ws.Range("E7") = Me.Box4.Value
    ws.Range("D9") = Me.Box5.Value
    ws.Range("B9") = Me.Box6.Value
    ws.Range("C9") = Me.Box7.Value
    ws.Range("C11") = Me.Box8.Value
    ws.Range("B14") = Me.Box9.Value
    ws.Range("F11") = Me.Box10.Value
    ws.Range("F12") = Me.Box11.Value
    ws.Range("F18") = Me.Box12.Value
    ws.Range("F17") = Me.Box13.Value
    ws.Range("F20") = Me.Box15.Value
    ws.Range("F21") = Me.Box16.Value
    ws.Range("A14") = Me.Box17.Value
    ws.Range("A17") = Me.Box18.Value
    ws.Range("A20") = Me.Box19.Value
    ws.Range("A23") = Me.Box20.Value
    ws.Range("b6") = Me.CBox1.Value & " " & Me.Box3.Value
       
          
    CBox1.Value = ""
    Box3.Value = ""
    Box4.Value = ""
    Box5.Value = ""
    Box6.Value = ""
    Box7.Value = ""
    Box8.Value = ""
    Box9.Value = ""
    Box10.Value = ""
    Box11.Value = ""
    Box12.Value = ""
    Box13.Value = ""
    Box15.Value = ""
    Box16.Value = ""
    Box17.Value = ""
    Box18.Value = ""
    Box19.Value = ""
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    End Sub
    Attached Files Attached Files
    Last edited by Sintek; 08-04-2016 at 07:48 AM.

  2. #2
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: If Statements in Userform TextBox to populate other textbox

    Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Dim ws As Worksheet, myval As Integer
    
    If Val(Box10) > 0 Then
        myval = 4
        Else
        myval = 1
    End If
    If CBox.Value = "" Then
    MsgBox "  PLEASE ENTER A WEEK NO"
    Exit Sub
    End If
    If CBox1.Value = "" Then
    MsgBox "     PLEASE SELECT A EMPLOYEE"
    Exit Sub
    End If
    If Not Evaluate("ISREF('" & CBox1.Value & "'!A1)") Then
        MsgBox "  GENERATE PAYSLIP"
        Exit Sub
    End If
    
    Set ws = Sheets(CBox1.Value)
    ws.Activate
    
    ws.Range("E5") = CBox.Value
    ws.Range("E6") = Me.Box.Value & " " & Me.Box1.Value & " " & Me.Box2.Value
    ws.Range("E7") = Me.Box4.Value
    ws.Range("D9") = Me.Box5.Value
    ws.Range("B9") = Me.Box6.Value
    ws.Range("C9") = Me.Box7.Value
    ws.Range("C11") = Me.Box8.Value
    ws.Range("B14") = Me.Box9.Value
    ws.Range("F11") = Me.Box10.Value
    ws.Range("F12") = Me.Box11.Value
    ws.Range("F18") = Me.Box12.Value * myval
    ws.Range("F17") = Me.Box13.Value * myval
    ws.Range("F20") = Me.Box15.Value
    ws.Range("F21") = Me.Box16.Value
    ws.Range("A14") = Me.Box17.Value
    ws.Range("A17") = Me.Box18.Value
    ws.Range("A20") = Me.Box19.Value
    ws.Range("A23") = Me.Box20.Value
    ws.Range("b6") = Me.CBox1.Value & " " & Me.Box3.Value
       
          
    CBox1.Value = ""
    Box3.Value = ""
    Box4.Value = ""
    Box5.Value = ""
    Box6.Value = ""
    Box7.Value = ""
    Box8.Value = ""
    Box9.Value = ""
    Box10.Value = ""
    Box11.Value = ""
    Box12.Value = ""
    Box13.Value = ""
    Box15.Value = ""
    Box16.Value = ""
    Box17.Value = ""
    Box18.Value = ""
    Box19.Value = ""
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    End Sub
    and

    Private Sub Box12_Change()
        OnlyNumbers
    End Sub

    Kind regards
    Leo

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: If Statements in Userform TextBox to populate other textbox

    Leo

    You are a star. Works like a charm.

    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] populate a listbox ased on textbox value in userform
    By justlearning123 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-09-2015, 06:48 PM
  2. Listbox and Userform to populate textbox - Help!
    By reyreyreyes in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-22-2015, 01:32 PM
  3. Populate TextBox from Module prior to opening TextBox
    By Dabbler39 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-05-2013, 05:50 PM
  4. [SOLVED] populate userform listbox from textbox input
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-05-2013, 10:05 AM
  5. [SOLVED] Populate UserForm textbox
    By jed38 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-06-2013, 02:05 PM
  6. VBA UDF to populate textbox in UserForm
    By grcaz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-16-2012, 08:03 AM
  7. Userform Textbox to populate with
    By Julesdude in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-12-2010, 10:49 AM

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