Conditional time formatting

eldaye

New Member
Joined
Aug 8, 2015
Messages
5
Please help!
I'm trying to set a variable dependent on some input by the user. The user inputs 2 different times; and also selects the date. I need the code to compare these times based on "within an hour AND same day", "outside an hour" AND same day", and "Not same day". It's currently not working, but i'm not sure as to why. Thanks in advance!
This is what i have so far:

dim day, timeC, timeR, timeA as string
dim nextrow as long
day = Format(TextBox2.Text, "mm dd yy")
timeC = Format(TextBox1.Text, "hh:mm")
timeR = Format(TextBox11.Text, "hh:mm")
If timeR < DateAdd("h", 1, timeC) And day = Date Then
timeA = 1​
ElseIf timeR > DateAdd("h", 1, timeC) And day = Date Then
timeA = 2​
ElseIf day <> Format(Date, "mm dd yy") Then
timeA = 3​
End If
nextrow = Sheets("tracking").Cells(Rows.Count, "A").End(xlUp).End(xlUp).Row + 1
If timeA = 1 Then
Sheets("tracking").Range("BA" & nextrow) = 1​
ElseIf timeA = 2 Then
Sheets("tracking").Range("BB" & nextrow) = 1​
ElseIf timeA = 3 then
Sheets("tracking").Range("BC" & nextrow) = 1​
End If
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
For the start try:
Code:
dim day, timeC, timeR, timeA [B]as integer
[/B]day = [B]CDate(TextBox2.Text)[/B]
timeC = [B]CDate(TextBox1.Text)[/B]
timeR = [B]CDate(TextBox11.Text)[/B]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,142
Members
452,615
Latest member
bogeys2birdies

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