The VBA module below creates a calendar. There are no eroors when the VBA runs, but I…
- User
The VBA module below creates a calendar. There are no eroors when the VBA runs, but I have noticed that the days of some of the months are not complete. For example, the current month September is only numbered to 29 October is only numbered to 30, November is only numbered to 29 December is only numbered to 30 and January is only numbered to 30.
Sub CreateCalendar() Dim ws As Worksheet Dim currDate As Date Dim rowNum As Integer Dim colNum As Integer Dim monthCounter As Integer
Set ws = ThisWorkbook.Sheets("Asset Calendar") ws.Range("A2:H60").ClearContents ' Set the initial date to the first day of the current month currDate = DateSerial(year(Date), month(Date), 1) ' Loop through the current month and the next four months For monthCounter = 0 To 4 ' Set the initial row number for each month rowNum = 2 + monthCounter * 11 ' Add the month name to column A ws.Cells(rowNum, 1).Value = Format(currDate, "MMMM YYYY") ws.Cells(rowNum, 1).Font.Bold = True ' Loop through the days of the month and populate the calendar grid with the appropriate dates Do While month(currDate) = month(currDate + 1) If Weekday(currDate, vbMonday) = 1 And Day(currDate) > 1 Then ' Insert an empty row after every row of days rowNum = rowNum + 2 End If colNum = Weekday(currDate, vbMonday) ' Set the column number based on the day of the week ws.Cells(rowNum, colNum + 1).Value = Day(currDate) ' Populate the day in the corresponding cell currDate = currDate + 1 ' Move to the next day Loop ' Move to the next month currDate = DateSerial(year(currDate), month(currDate) + 1, 1) Next monthCounterEnd Sub
- Assistant
- User
the code is running in a continous loop
- Assistant
- User
The dates are now correct, but I have lost the extra row space after each row of dates
- Assistant
- User
In my excel sheet 'Booking', I have a list box in A2. The list is sourced from sheet 'Assets' A2:A8 The values in sheet 'Assets' A2:A8 correspond to the header values in sheet 'Assets' B1:H1 When I choose a value in sheet 'Booking' A2, I want the list box values in sheet 'Booking' A4 to correspond to the column values in sheet 'Assets' from row 2 downwards where the value in sheet 'Bookings' A2 is the eqaul to the header value in sheet 'Assets' B1 to H1 Can you show me how to do this.
- Assistant
- User
My list box in A2 is created by using Data Validation
- Assistant
- User
When it finds the column values, I want the data populated to column L from row 2 downwards
- Assistant
- User
Can you please write me a formula that will do this If at least one cell in D3:J3 is not blank, then C3 = C2
- Assistant
Certainly! You can achieve this using the
IFandCOUNTAfunctions in Excel to check if at least one cell in the rangeD3:J3is not blank. Here’s the formula you can use in cellC3:=IF(COUNTA(D3:J3) > 0, C2, "")Explanation of the Formula:
-
COUNTA(D3:J3): This function counts the number of non-empty cells in the specified range (
D3:J3). -
IF(COUNTA(D3:J3) > 0, C2, ""):
- If the count of non-empty cells is greater than 0 (meaning at least one cell is not blank), it returns the value of
C2. - If all cells in
D3:J3are blank, it returns an empty string (""), which means nothing will be displayed inC3.
- If the count of non-empty cells is greater than 0 (meaning at least one cell is not blank), it returns the value of
Steps to Use the Formula:
- Click on cell
C3where you want to enter the formula. - Paste the formula above into the formula bar.
- Press Enter to apply the formula.
Now, whenever there is at least one non-blank cell in , will display the value from . If all cells in are blank, will remain blank.
-