• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA - small code required

vasim

Member
How can I make this code small....


Private Sub Calendar1_Click()

'Calendar value in textbox

UserForm1.TextBox13.Value = Format(Calendar1.Value, "dd/mmm/yyyy")

Calendar1.Visible = False

End Sub


Private Sub Calendar2_Click()

'Calendar value in textbox

UserForm1.TextBox14.Value = Format(Calendar2.Value, "dd/mmm/yyyy")

Calendar2.Visible = False

End Sub


Private Sub Calendar3_Click()

'Calendar value in textbox

UserForm1.TextBox15.Value = Format(Calendar3.Value, "dd/mmm/yyyy")

Calendar3.Visible = False

End Sub


Private Sub Calendar4_Click()

'Calendar value in textbox

UserForm1.TextBox16.Value = Format(Calendar4.Value, "dd/mmm/yyyy")

Calendar4.Visible = False

End Sub


Private Sub Calendar5_Click()

'Calendar value in textbox

UserForm1.TextBox17.Value = Format(Calendar5.Value, "dd/mmm/yyyy")

Calendar5.Visible = False

End Sub


Private Sub Calendar6_Click()

'Calendar value in textbox

UserForm1.TextBox28.Value = Format(Calendar6.Value, "dd/mmm/yyyy")

Calendar6.Visible = False

End Sub


Private Sub Calendar7_Click()

'Calendar value in textbox

UserForm1.TextBox29.Value = Format(Calendar7.Value, "dd/mmm/yyyy")

Calendar7.Visible = False

End Sub


Private Sub Calendar8_Click()

'Calendar value in textbox

UserForm1.TextBox31.Value = Format(Calendar8.Value, "dd/mmm/yyyy")

Calendar8.Visible = False

End Sub


Private Sub Calendar9_Click()

'Calendar value in textbox

UserForm1.TextBox30.Value = Format(Calendar9.Value, "dd/mmm/yyyy")

Calendar9.Visible = False

End Sub
 
Hello,


You can construct this using IF clause...but may I request you to please upload your workbook so that we can test the code with the data before posting it.


Kaushik
 
Since it's a different text box for each control, and there's no self-reference name/shortcut for controls, I'm not sure we can shorten it up much. =(


One thought, do you really need multiple calendar controls? Perhaps you could just use 1, and then show/hide it as needed to get values for your text boxes.
 
Hi, Indian!

Deleting 9 calendar and 9 text box controls is suitable for you?

It'd be the better approach to the most minimalist option...

Regards!
 
Back
Top