- 29.5k
- 16
- 45
- 201
VBA code optimisation needed userform with textboxes and dates to show timeline
I am writing the following VBA code to make a timeline, which I will be using for other parts of the code later on for other calculations and output. I have a userform where thethe following number of text boxes and labels are present:
- wkbox* and intbox* are textboxes which have weeks as input from user. wkbox* is duration of a stage, intbox* is interval between two stages.
- date* are labels which give output as dates when each stage starts.
- mpsd is the input date for the entire timeline start date from mpsd.text box, which is considered as the start date in my code below
Public mpsd as date
Private Sub Setbutton_Click()
Me.date1 = mpsd
Me.date2 = DateAdd("d", ((wkbox1 * 5) + (intbox1 * 5)), date1)
Me.date3 = DateAdd("d", ((wkbox2 * 5) + (intbox2 * 5)), date2)
Me.date4 = DateAdd("d", ((wkbox3 * 5) + (intbox3 * 5)), date3)
Me.date5 = DateAdd("d", ((wkbox4 * 5) + (intbox4 * 5)), date4)
Me.date6 = DateAdd("d", ((wkbox5 * 5) + (intbox5 * 5)), date5)
Me.date7 = DateAdd("d", ((wkbox6 * 5) + (intbox6 * 5)), date6)
Me.date8 = DateAdd("d", ((wkbox7 * 5) + (intbox7 * 5)), date7)
Me.date9 = DateAdd("d", ((wkbox8 * 5) + (intbox8 * 5)), date8)
Me.date10 = DateAdd("d", ((wkbox9 * 5) + (intbox9 * 5)), date9)
Me.date11 = DateAdd("d", ((wkbox10 * 5) + (intbox10 * 5)), date10)
Me.date12 = DateAdd("d", ((wkbox11 * 5) + (intbox11 * 5)), date11)
End sub
I was trying to think if there is a way to optimise this code through for
,case
, etc.
I
I am very new to VBA, so am not able to think how I can reduce this to a maybe 3 line for
or case
code to speed up the running of the code.
(This is just a part of a big schedule planner code, so any sec saved is good for me.) Is there a way to do it? Thank you.
VBA code optimisation needed
I am writing the following VBA code to make a timeline, which I will be using for other parts of the code later on for other calculations and output. I have a userform where the following number of text boxes and labels are present:
- wkbox* and intbox* are textboxes which have weeks as input from user. wkbox* is duration of a stage, intbox* is interval between two stages.
- date* are labels which give output as dates when each stage starts.
- mpsd is the input date for the entire timeline start date from mpsd.text box, which is considered as the start date in my code below
Public mpsd as date
Private Sub Setbutton_Click()
Me.date1 = mpsd
Me.date2 = DateAdd("d", ((wkbox1 * 5) + (intbox1 * 5)), date1)
Me.date3 = DateAdd("d", ((wkbox2 * 5) + (intbox2 * 5)), date2)
Me.date4 = DateAdd("d", ((wkbox3 * 5) + (intbox3 * 5)), date3)
Me.date5 = DateAdd("d", ((wkbox4 * 5) + (intbox4 * 5)), date4)
Me.date6 = DateAdd("d", ((wkbox5 * 5) + (intbox5 * 5)), date5)
Me.date7 = DateAdd("d", ((wkbox6 * 5) + (intbox6 * 5)), date6)
Me.date8 = DateAdd("d", ((wkbox7 * 5) + (intbox7 * 5)), date7)
Me.date9 = DateAdd("d", ((wkbox8 * 5) + (intbox8 * 5)), date8)
Me.date10 = DateAdd("d", ((wkbox9 * 5) + (intbox9 * 5)), date9)
Me.date11 = DateAdd("d", ((wkbox10 * 5) + (intbox10 * 5)), date10)
Me.date12 = DateAdd("d", ((wkbox11 * 5) + (intbox11 * 5)), date11)
End sub
I was trying to think if there is a way to optimise this code through for
,case
, etc.
I am very new to VBA, so am not able to think how I can reduce this to a maybe 3 line for
or case
code to speed up the running of the code.(This is just a part of a big schedule planner code, so any sec saved is good for me.)
Is there a way to do it?
Thank you.
userform with textboxes and dates to show timeline
I am writing the following VBA code to make a timeline, which I will be using for other parts of the code later on for other calculations and output. I have a userform where the following number of text boxes and labels are present:
- wkbox* and intbox* are textboxes which have weeks as input from user. wkbox* is duration of a stage, intbox* is interval between two stages.
- date* are labels which give output as dates when each stage starts.
- mpsd is the input date for the entire timeline start date from mpsd.text box, which is considered as the start date in my code below
Public mpsd as date
Private Sub Setbutton_Click()
Me.date1 = mpsd
Me.date2 = DateAdd("d", ((wkbox1 * 5) + (intbox1 * 5)), date1)
Me.date3 = DateAdd("d", ((wkbox2 * 5) + (intbox2 * 5)), date2)
Me.date4 = DateAdd("d", ((wkbox3 * 5) + (intbox3 * 5)), date3)
Me.date5 = DateAdd("d", ((wkbox4 * 5) + (intbox4 * 5)), date4)
Me.date6 = DateAdd("d", ((wkbox5 * 5) + (intbox5 * 5)), date5)
Me.date7 = DateAdd("d", ((wkbox6 * 5) + (intbox6 * 5)), date6)
Me.date8 = DateAdd("d", ((wkbox7 * 5) + (intbox7 * 5)), date7)
Me.date9 = DateAdd("d", ((wkbox8 * 5) + (intbox8 * 5)), date8)
Me.date10 = DateAdd("d", ((wkbox9 * 5) + (intbox9 * 5)), date9)
Me.date11 = DateAdd("d", ((wkbox10 * 5) + (intbox10 * 5)), date10)
Me.date12 = DateAdd("d", ((wkbox11 * 5) + (intbox11 * 5)), date11)
End sub
I was trying to think if there is a way to optimise this code through for
,case
, etc.
I am very new to VBA, so am not able to think how I can reduce this to a maybe 3 line for
or case
code to speed up the running of the code.
(This is just a part of a big schedule planner code, so any sec saved is good for me.) Is there a way to do it?
wkbox* and intbox* are textboxes which have weeks as input from user. wkbox* is duration of a stage, intbox* is interval between two stages.
wkbox* and intbox* are textboxes which have weeks as input from user. wkbox* is duration of a stage, intbox* is interval between two stages.date* are labels which give output as dates when each stage starts.
date* are labels which give output as dates when each stage starts.mpsd is the input date for the entire timeline start date from mpsd.text box, which is considered as the start date in my code below
Public mpsd as date
Private Sub Setbutton_Click()
mpsd is the input date for the entire timeline start date from mpsd.text box, which is considered as the start date in my code belowMe.date1 = mpsd Me.date2 = DateAdd("d", ((wkbox1 * 5) + (intbox1 * 5)), date1) Me.date3 = DateAdd("d", ((wkbox2 * 5) + (intbox2 * 5)), date2) Me.date4 = DateAdd("d", ((wkbox3 * 5) + (intbox3 * 5)), date3) Me.date5 = DateAdd("d", ((wkbox4 * 5) + (intbox4 * 5)), date4) Me.date6 = DateAdd("d", ((wkbox5 * 5) + (intbox5 * 5)), date5) Me.date7 = DateAdd("d", ((wkbox6 * 5) + (intbox6 * 5)), date6) Me.date8 = DateAdd("d", ((wkbox7 * 5) + (intbox7 * 5)), date7) Me.date9 = DateAdd("d", ((wkbox8 * 5) + (intbox8 * 5)), date8) Me.date10 = DateAdd("d", ((wkbox9 * 5) + (intbox9 * 5)), date9) Me.date11 = DateAdd("d", ((wkbox10 * 5) + (intbox10 * 5)), date10) Me.date12 = DateAdd("d", ((wkbox11 * 5) + (intbox11 * 5)), date11) End sub
Public mpsd as date
Private Sub Setbutton_Click()
Me.date1 = mpsd
Me.date2 = DateAdd("d", ((wkbox1 * 5) + (intbox1 * 5)), date1)
Me.date3 = DateAdd("d", ((wkbox2 * 5) + (intbox2 * 5)), date2)
Me.date4 = DateAdd("d", ((wkbox3 * 5) + (intbox3 * 5)), date3)
Me.date5 = DateAdd("d", ((wkbox4 * 5) + (intbox4 * 5)), date4)
Me.date6 = DateAdd("d", ((wkbox5 * 5) + (intbox5 * 5)), date5)
Me.date7 = DateAdd("d", ((wkbox6 * 5) + (intbox6 * 5)), date6)
Me.date8 = DateAdd("d", ((wkbox7 * 5) + (intbox7 * 5)), date7)
Me.date9 = DateAdd("d", ((wkbox8 * 5) + (intbox8 * 5)), date8)
Me.date10 = DateAdd("d", ((wkbox9 * 5) + (intbox9 * 5)), date9)
Me.date11 = DateAdd("d", ((wkbox10 * 5) + (intbox10 * 5)), date10)
Me.date12 = DateAdd("d", ((wkbox11 * 5) + (intbox11 * 5)), date11)
End sub
wkbox* and intbox* are textboxes which have weeks as input from user. wkbox* is duration of a stage, intbox* is interval between two stages.
date* are labels which give output as dates when each stage starts.
mpsd is the input date for the entire timeline start date from mpsd.text box, which is considered as the start date in my code below
Public mpsd as date
Private Sub Setbutton_Click()Me.date1 = mpsd Me.date2 = DateAdd("d", ((wkbox1 * 5) + (intbox1 * 5)), date1) Me.date3 = DateAdd("d", ((wkbox2 * 5) + (intbox2 * 5)), date2) Me.date4 = DateAdd("d", ((wkbox3 * 5) + (intbox3 * 5)), date3) Me.date5 = DateAdd("d", ((wkbox4 * 5) + (intbox4 * 5)), date4) Me.date6 = DateAdd("d", ((wkbox5 * 5) + (intbox5 * 5)), date5) Me.date7 = DateAdd("d", ((wkbox6 * 5) + (intbox6 * 5)), date6) Me.date8 = DateAdd("d", ((wkbox7 * 5) + (intbox7 * 5)), date7) Me.date9 = DateAdd("d", ((wkbox8 * 5) + (intbox8 * 5)), date8) Me.date10 = DateAdd("d", ((wkbox9 * 5) + (intbox9 * 5)), date9) Me.date11 = DateAdd("d", ((wkbox10 * 5) + (intbox10 * 5)), date10) Me.date12 = DateAdd("d", ((wkbox11 * 5) + (intbox11 * 5)), date11) End sub
- wkbox* and intbox* are textboxes which have weeks as input from user. wkbox* is duration of a stage, intbox* is interval between two stages.
- date* are labels which give output as dates when each stage starts.
- mpsd is the input date for the entire timeline start date from mpsd.text box, which is considered as the start date in my code below
Public mpsd as date
Private Sub Setbutton_Click()
Me.date1 = mpsd
Me.date2 = DateAdd("d", ((wkbox1 * 5) + (intbox1 * 5)), date1)
Me.date3 = DateAdd("d", ((wkbox2 * 5) + (intbox2 * 5)), date2)
Me.date4 = DateAdd("d", ((wkbox3 * 5) + (intbox3 * 5)), date3)
Me.date5 = DateAdd("d", ((wkbox4 * 5) + (intbox4 * 5)), date4)
Me.date6 = DateAdd("d", ((wkbox5 * 5) + (intbox5 * 5)), date5)
Me.date7 = DateAdd("d", ((wkbox6 * 5) + (intbox6 * 5)), date6)
Me.date8 = DateAdd("d", ((wkbox7 * 5) + (intbox7 * 5)), date7)
Me.date9 = DateAdd("d", ((wkbox8 * 5) + (intbox8 * 5)), date8)
Me.date10 = DateAdd("d", ((wkbox9 * 5) + (intbox9 * 5)), date9)
Me.date11 = DateAdd("d", ((wkbox10 * 5) + (intbox10 * 5)), date10)
Me.date12 = DateAdd("d", ((wkbox11 * 5) + (intbox11 * 5)), date11)
End sub