Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

fixing problem show numbers of days correctly on calendar into userform

0

hello 

actually  i  try desighning the calendar  on userform because  i  have   occasions of  days   i  would  highlight theses days  and  show  comments on textbox  on userform  i  can't  do  that  by ready  tool calendar   so   i face  a problem  about  the numbers  of  days  it  begins  from 2  not  1   and  if  i  choose  the  month  it  stays  the  locate  numbers of days  in  the  same  place into  textbox  every month i choosed   if  my  explenation doesn't  clear   please  check  my  file  you  will understand it 

this my code

Private Sub ComboBox1_Change()
For x = 1 To 38
Me("textbox" & x) = ""
Me("textbox" & x).BackColor = vbWhite
Next x
mn = Me.ComboBox1.Value
yr = Format(Date, "yyyy")
On Error Resume Next
a = Application.WorksheetFunction.Weekday(1 & "/" & mn & "/" & yr, 1)
Me("textbox" & a) = 1
For i = 1 To 38
Me("textbox" & a + i) = Format(CDate(i + 1 & "/" & mn & "/" & yr), "dd")
m = CDate(Me("textbox" & i) & "/" & mn & "/" & yr)
If m = Date Then
Me("textbox" & i).BackColor = vbRed
End If
Next i

End Sub



Private Sub UserForm_Initialize()
For i = 1 To 12
a = 1 & "/" & i & "/" & 2020
Me.ComboBox1.AddItem Format(a, "mmmm")
Next i
Me.ComboBox1.Value = Format(Date, "mmmm")
For x = 1 To 7
Me("textbox" & 42 + x) = Format(x, "ddd")
Next x
End Sub
Answer
Discuss

Discussion

If you really want help with your "code" I suggest that you start by declaring all your variables, giving meaningful names to them so that yourself and others can see what you are trying to do.
After that run your code until it encounters the first error. Then ask a question about that error. This is to make sure that you face every problem yourself before you dump it on us.
Variatus (rep: 4889) Aug 20, '20 at 4:04 am
Add to Discussion

Answers

0
Selected Answer

Don't go there, Leopard. Writing code for a calendar is quite complex. The problems you have discovered are just the tip of the iceberg.

I attach code for a celendar I wrote in 2014 and still use today. There are some minor bugs in it but they don't bother me. So I didn't fix them. They relate to the sizability and conversion of the calendar to other languages. Chances are you won't come up against them any time soon.

Yes, you can change the size of the calendar on the screen and determine the location where you want the display to pop up on the screen . You can also change the first day of the week. The code is quite well commented. Take a tour. Start with the buttons on the "Calendar Test" tab. Learn how to call the app by studying the code in the module Test014.

Discuss

Discussion

thanks variatous  for  your  calendar  but  unfortunately  it  doesn't help me  because  youe  use  datepicker tool   i can't  specialize some  days  and  highlight  into  calender  but  my  form  i  use  textbox  to  do  that , i was would   some  help to fixing  my  code   to  do  that 
leopard (rep: 88) Aug 19, '20 at 11:55 pm
Take another look, Leopard. My program replaces the DatePicker tool. It doesn't use it at all.
Variatus (rep: 4889) Aug 20, '20 at 3:54 am
sorry  about  it   i  see userform's name  datepicke  i    thought  you  use  it   but   when  i  go  developer  thab  and   i  take  a look  userform     it  hiddin  very buttons     what  use   textboxs  or  lables   about   the  numbers   and  how  can  i  show  the  buttons   before  run  userform  until  to  make   some  days  highligh  background  when  the  reaches  it  show 
leopard (rep: 88) Aug 20, '20 at 4:34 am
The form creates the text boxes which are the buttons on the fly. They don't exist before the code is run.
Variatus (rep: 4889) Aug 20, '20 at 8:53 am
what i'm looking for  is  how  i  can link accassion   the  days   with  the calendar on userform   i have  the  days  in col a  and  the  date  in col  b  and  the  c  the name of accassion    theses cols  are existed in sheet's name is sheet2   i  made  this  in combobox1 according  my  file  but   your  file  i no  know  how  i  make it 
For b = 2 To sheet1.Range("a10000").End(xlUp).Row
    If sheet1.Cells(b, 2) = m And Me("textbox" & i) <> "" Then
    Me("textbox" & i).BackColor = &HE0E0E0
    Me("textbox" & i).ControlTipText = sheet1.Cells(b, 3)
    End If
    Next b
Next i
leopard (rep: 88) Aug 20, '20 at 11:57 am
Me("textbox" & i) is improper syntax. Try Me.Controls("TextBox" & I).Value.
I shall now end this thread. If you have more questions please start a new one.
Variatus (rep: 4889) Aug 20, '20 at 8:45 pm
thanks variatus for   everything 
leopard (rep: 88) Aug 21, '20 at 6:33 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login