Excel calendar vba
-
Good morning Victor, Can you please help me I am very new to vba and would appreciate some help with the code for the calendar on my worksheet. I have a button that opens a userform produced calendar. Here is the piece of code I have so far:- Private Sub Calendar1_Click() tabname = Format(Me.Calendar1.Value, "mmmm") theday = Day(Me.Calendar1.Value) ActiveSheet.Cells(theday, 1).Select End Sub When Jan 1st is clicked it takes the cursor to cell A1, Jan 2nd takes you to A2 and so on for the rest of January. But when February or any subsequent month is selected and the 1st of this month is clicked the cursor reverts back to cell A1. I need the calendar to continue vertically down the worksheet for the complete year and beyond. In other words if Jan 1st is on cell A1 then the Feb 1st need to go to cell A32 and so on for subsequent months and years. Lastly my worksheet has headers along the top four rows so I really need the date of Jan 1st to start on row B6. I have worked it out that I can get the cursor to start in column B by changing the line of my code from 'ActiveSheet.Cells(theday, 1).Select' to 'ActiveSheet.Cells(theday, 2).Select' but cannot work out how to get Jan 1st to start on row B6 Sorry if my explanation lacks the correct terms for VBA language and hope you feel happy to help. Best Alan
-
Answer:
I'm happy to help. I made some small changes to your code so that it will continue to select the cells vertically down the worksheet for the dates selected in the calendar. -Private Sub Calendar1_Click() tabname = Format(Me.Calendar1.Value, "mmmm") theday = Day(Me.Calendar1.Value) themonth = Month(Me.Calendar1.Value) theyear = Year(Me.Calendar1.Value) theday_adj = CLng(Application.WorksheetFunction.EoMonth(DateSerial(theyear, 1, 1), themonth - 2) - DateSerial(theyear, 1, 1)) + 1 + theday ActiveSheet.Cells(theday_adj, 1).Select End Sub - The following code will get Jan 1st to start on row B6. ActiveSheet.Cells(theday + 5, 2).Select Please test it out and let me know if it works well.
Miningco.com Visit the source
Related Q & A:
- How to add calendar events in other calendar in Android?Best solution by Stack Overflow
- How I can find string in excel with vba?Best solution by Stack Overflow
- How to add calendar event in Yahoo calendar?Best solution by Stack Overflow
- How to covert csv file to excel and back excel file to csv in python?Best solution by completecampaigns.com
- How do I sync my blackberry calendar to my Google calendar?Best solution by Quora
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.