User Form Question

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
946
Office Version
  1. 2016
Platform
  1. Windows
Hello All,
I'm having a little difficulty with learning about User Form's

My Code Thus Far:
Code:
 [COLOR=#339933]'While Loop Checks for Data Beginning In Line 17[/COLOR] 
RowCounter = 17
    While Cells(RowCounter, 2).Value <> ""
        RowCounter = RowCounter + 1
    Wend    
[COLOR=#339900]'Data Input Into Excel Sheet[/COLOR]
    Cells(RowCounter, 2).Value = Tbx_Date.Text
    Cells(RowCounter, 3).Value = Tbx_Time.Value

So, My User Form has two fields to fill in:
1. "Date Field"
2. "Time Field"

When I fill in the Date Field, the User Form enters the date in RANGE(B17), as it should, and continues with B18, B19 as new dates are entered. So the Date Field is working Correctly.

My "Time Field" is not working correctly. When I enter a number ie: 1.5, the code faults on:
Cells(RowCounter, 3).Value = Tbx_Time.Value

What I'm trying to accomplish, is the Date in B17 and the corresponding time in C18.

Thanks for the help
excel 2013

PS, at this time, I have no declarations, which is probably wrong...
 
Last edited:

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
.
Here is a simple database project to draw from :

Code:
Option Explicit
Private Sub btnCancel_Click()
    Unload Me
End Sub


Private Sub btnOK_Click()
    Dim ws As Worksheet
    Set ws = Worksheets("Customers")
    Dim newRow As Long
    newRow = Application.WorksheetFunction.CountA(ws.Range("A:A")) + 1
    ws.Cells(newRow, 1).Value = Me.txtFirstName.Value
    ws.Cells(newRow, 2).Value = Me.txtSurname.Value
End Sub
Sub CommandButton1_Click()
    Selection.EntireRow.Delete
End Sub

Download : https://www.amazon.com/clouddrive/share/0b71HYeBuQlKBNiQrUoxmtRx51Y3OnNzFncBfD4qJW7
 
Upvote 0
You said:
When I enter a number ie: 1.5

If this is suppose to be a time
Explain to me what 1.5 is

The time is 1.5

?????

But even so it should work but When you enter 1.5 what do you want the end result to look like
 
Upvote 0
You said:
When I enter a number ie: 1.5

If this is suppose to be a time
Explain to me what 1.5 is

The time is 1.5



When you enter 1.5 what do you want the end result to look like

1.5 should appear in C17 has the number 1.5. If I enter 10.2, then the number will be 10.2 in C17.
The number is the amount of hours worked for the Date entered.
If i enter a date of: 11-1-17. And a work time of 8.0, then the excel sheet will read in B17 as 11-1-2017 and in C17 the number (number format) as 8.0.
thanks
 
Last edited:
Upvote 0
OK.

And are you attempting to put these values in the last row with data plus 1

So if Column "A" has data already in rows 1 to 20 you want this data your now entering to be put into row 21

Is that what you want?

If so you do not need a do while loop

If that is what you want we can write you a script to do this
 
Upvote 0
If what I asked about is true then use this script.

Code:
Private Sub CommandButton2_Click()
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "B").End(xlUp).Row + 1
Cells(Lastrow, 3).Value = Tbx_Time.Value
Cells(Lastrow, 2).Value = Tbx_Date.Value
End Sub
 
Upvote 0
OK.
And are you attempting to put these values in the last row with data plus 1
So if Column "A" has data already in rows 1 to 20 you want this data your now entering to be put into row 21
Is that what you want?
If so you do not need a do while loop
If that is what you want we can write you a script to do this

Sort of.
Because the pay week is a 7 day block, then day 1 would begin on B17 day date, and pay time on C17
Day 2 would be shown in B18 and pay time in C18
Day 3 would be shown in B19 and pay time in C19...

At the end of the pay week, I have a clear button which simply resets the worksheet, and I start with a new pay week beginning again on B17 and C17. I'm not concerned with saving past pay weeks.

I think this Dropbox Link will work for my worksheet:
https://www.dropbox.com/s/bqdoekpaxeg03ti/Time WorkSheet Macro - Copy.xlsm?dl=0

Thanks
 
Last edited:
Upvote 0
Try this:
Code:
Private Sub CommandButton2_Click()
'Modified 11-19-17 1:50 PM EST
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "B").End(xlUp).Row + 1
If Lastrow < 17 Then Lastrow = 17
Cells(Lastrow, 3).Value = Tbx_Time.Value
Cells(Lastrow, 2).Value = Tbx_Date.Value
End Sub
 
Upvote 0
The problem is that the textbox is called Tbx_Upper not Tbx_Time
 
Upvote 0
Try this:
Code:
Private Sub CommandButton2_Click()
'Modified 11-19-17 1:50 PM EST
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "B").End(xlUp).Row + 1
If Lastrow < 17 Then Lastrow = 17
Cells(Lastrow, 3).Value = Tbx_Time.Value
Cells(Lastrow, 2).Value = Tbx_Date.Value
End Sub

Here's some links of what my worksheet looks like with the User Form,
And the fault that I keep getting:
https://www.dropbox.com/s/dz6ypw8y7b2beie/Time Clock Worksheet.JPG?dl=0
https://www.dropbox.com/s/jfft9i7z0s1iwfv/Time Clock Worksheet Fault.JPG?dl=0

So, When I input data in the Date and Time fields of the Shown User Form, then hit the Add Button, the data is entered into the excel sheet, When I hit the Clear button on the User Form, it will clear my Date and Time input fields on the User Form, so I can add more data.

The worksheet Click "Clear" Button Clears the worksheet from B17 on, and the other click command button simply shows the User Form


Thanks for the help
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top