Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I've got the following probl

Status
Not open for further replies.

Joep1972

Technical User
Nov 24, 2002
13
NL
Hi,

I've got the following problem,
when I chose in the calendar of my userform a date in november it doesn't work can somebody have look what is the problem. HELP I'm getting mad.


Private Sub CommandButton3_Click()
If Me.Calendar1.Day <= Day(&quot;301102&quot;) And Me.Calendar1.Day >= Day(&quot;11102&quot;) Then
Worksheets(&quot;Budget maand November 2002&quot;).Cells(13, 3).Value = Me.TextBox1.Text
Sheets(&quot;Budget maand November 2002&quot;).Cells(13, 4) = Me.Calendar1.Day
Sheets(&quot;Budget maand November 2002&quot;).Activate
End If
If Me.Calendar1.Day <= Day(&quot;311203&quot;) And Me.Calendar1.Day >= Day(&quot;11202&quot;) Then
Worksheets(&quot;Budget Maand December 2002&quot;).Cells(13, 3).Value = Me.TextBox1.Text
Sheets(&quot;Budget Maand December 2002&quot;).Cells(13, 4) = Me.Calendar1.Day
Sheets(&quot;Budget Maand December 2002&quot;).Activate
End If
Unload Me
End Sub

Many many thx
 
[bugeyed] It looks like you're working too hard. Try to simplify your logic:
Code:
Private Sub CommandButton3_Click()
  Dim strSheet As String
  
  strSheet = &quot;Budget maand &quot; & Format(Calendar1, &quot;mmmm&quot;) & &quot; &quot; & Year(Calendar1)
  
  With Sheets(strSheet)
    .Cells(13, 3).Value = Me.TextBox1.Text
    .Cells(13, 4) = Calendar1.Value
    .Activate
  End With
  
  Unload Me
  
End Sub

With this logic, as long as your sheet names use the same format, you'll never have to change the code.
VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top