VB help

Please can you help?

1.I'd like to amend the VB code so that txtHrs1, txtHrs2, txtMins1 and txtMins2 are restricted to only 2 characters on input.
2.Currently the user form brings back the value in Columns B, V, I or W on any given row.
3. If no date has been entered I would like for the textboxes to today’s date.
4.If the cell is currently empty, would it be possible to format the userform text to blue?  
Textbox1, Textbox2, Textbox3 & Textbox4 dev3.xls
Kiwi-123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wchhCommented:
Amend Macro as below:
Private Sub UserForm_Initialize()


    Set rngStart = Cells(ActiveCell.Row, "B")
    With rngStart

            TextBox1.Value = Format(.Value, "ddd dd/mm/yyyy")
            TextBox2.Value = Format(.Offset(, 7).Value, "ddd dd/mm/yyyy")
            TextBox3.Value = Format(.Offset(, 20).Value, "ddd dd/mm/yyyy")
            TextBox4.Value = Format(.Offset(, 21).Value, "ddd dd/mm/yyyy")
            txtHrs1.Value = Format(.Offset(, 7).Value, "HH")
            txtMins1.Value = Format(Minute(.Offset(, 7).Value), "00")
            txtHrs2.Value = Format(.Offset(, 21).Value, "HH")
            txtMins2.Value = Format(Minute(.Offset(, 21).Value), "00")
            TextBox5.Text = VBA.Environ("USERNAME")
            
    End With
    '<------Begin of Insert
    '1.I'd like to amend the VB code so that txtHrs1, txtHrs2, txtMins1 and txtMins2 are restricted to only 2 characters on input.
    txtHrs1.MaxLength = 2
    txtHrs2.MaxLength = 2
    txtMins1.MaxLength = 2
    txtMins2.MaxLength = 2
    '2.Currently the user form brings back the value in Columns B, V, I or W on any given row.
    '3.If no date has been entered I would like for the textboxes to today’s date.
    '4.If the cell is currently empty, would it be possible to format the userform text to blue
    'Textbox1, Textbox2, Textbox3 & Textbox4
    If TextBox1.Value = "" Then
        TextBox1.Value = Format(Now, "ddd dd/mm/yyyy")
        TextBox1.ForeColor = vbBlue
    End If
    If TextBox2.Value = "" Then
        TextBox2.Value = Format(Now, "ddd dd/mm/yyyy")
        TextBox2.ForeColor = vbBlue
    End If
    If TextBox3.Value = "" Then
        TextBox3.Value = Format(Now, "ddd dd/mm/yyyy")
        TextBox3.ForeColor = vbBlue
    End If
    If TextBox4.Value = "" Then
        TextBox4.Value = Format(Now, "ddd dd/mm/yyyy")
        TextBox4.ForeColor = vbBlue
    End If
    '<------End of Insert
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wchhCommented:
1.I'd like to amend the VB code so that txtHrs1, txtHrs2, txtMins1 and txtMins2 are restricted to only 2 characters on input.
--> You can also change Maxlength from 0 to 2 for textbox property.
0
Kiwi-123Author Commented:
Many thanks for your help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.