BeachBum
08-01-2016, 12:30 AM
Hi,
I am very new to the forum and the world of VBA so apologies if I don't explain this well.
I need to write a code that allows a user to input the number of variables and then for each of those variables ask a start time and an end time. These times will be used in a later code to separate large sections of data.
So for instance, the user would execute the code which will ask for a number of sessions n. The code will then generate 2n variables (session_start(i), session_end(i) where i = 1 to n). Each of these require a user input of a time, for example session_start1 = 9:00 , session_end1 = 11:00, session_start2 = 11:30...etc.
This is what I have so far:
Sub UserSessionInput()
Dim Sessions() As Variant, n As Variant, Session_start() As String, Session_end() As String
Dim i As Integer
n = InputBox("Please enter the number of Sessions per day:", "Survey Sessions")
ReDim Sessions(0 To noSessions, 2)
For i = 0 To n
Session_start(i) = InputBox("Enter session start time in HH:MM")
Session_end(i) = InputBox("Enter session end time in HH:MM")
Next i
End Sub
As I said, I am very new to VBA and unfortunately I am stuck now.
I also know that there will be an issue with the time format but not sure how to tackle that.
Ultimately I believe the array should be something like below with all the values being input by the user.
1
Session_start(1)
Session_end(1)
2
Session_start(2)
Session_end(2)
:
:
:
n
Session_start(n)
Session_end(n)
Any help is greatly appreciated. Thanks
I am very new to the forum and the world of VBA so apologies if I don't explain this well.
I need to write a code that allows a user to input the number of variables and then for each of those variables ask a start time and an end time. These times will be used in a later code to separate large sections of data.
So for instance, the user would execute the code which will ask for a number of sessions n. The code will then generate 2n variables (session_start(i), session_end(i) where i = 1 to n). Each of these require a user input of a time, for example session_start1 = 9:00 , session_end1 = 11:00, session_start2 = 11:30...etc.
This is what I have so far:
Sub UserSessionInput()
Dim Sessions() As Variant, n As Variant, Session_start() As String, Session_end() As String
Dim i As Integer
n = InputBox("Please enter the number of Sessions per day:", "Survey Sessions")
ReDim Sessions(0 To noSessions, 2)
For i = 0 To n
Session_start(i) = InputBox("Enter session start time in HH:MM")
Session_end(i) = InputBox("Enter session end time in HH:MM")
Next i
End Sub
As I said, I am very new to VBA and unfortunately I am stuck now.
I also know that there will be an issue with the time format but not sure how to tackle that.
Ultimately I believe the array should be something like below with all the values being input by the user.
1
Session_start(1)
Session_end(1)
2
Session_start(2)
Session_end(2)
:
:
:
n
Session_start(n)
Session_end(n)
Any help is greatly appreciated. Thanks