PDA

View Full Version : vba que: coding for dynamic calendar; multiple drop down lists outputting to new shee



Mat-
11-08-2021, 03:57 PM
Hi - please kindly assist - and thank you in advance
version: Microsoft® Excel® for Microsoft 365 MSO (Version 2110 Build 16.0.14527.20234) 64-bit
the below coding runs only for column 1 on the automatically created worksheet (and any subsequent sheets (worksheets result from a named range within a dynamic calendar. – Thus, when i click/change the date or year within a dynamic calendar, data outputs to the auto created sheet labeled as the appropriate year.
The Goal and outcome: output data that is typed into "schedule" worksheet (from BOTH column AH and AI dropdown lists) into subsequent auto created sheets please note- data outputs to a column which is unlabeled -but by default/definition of coding means the top column and row refers to a named range day/date of the year corresponding to the "scheldule" worksheet created. (this means that if I type data into the schedule worksheet into drop downs in column AH and have chosen year 2020, January, 1st, then the data will appear in the 2020 worksheet 1st column which references automatically january 1, 2020. Likewise, if a chose a different year, data for the appropriate day/month will populate on a different sheet-entitled 2019, or 2021. I need the data for both columns AH and AI to appear on each subsequent sheet.


Option Explicit
Dim YearNm As Long, DayCol As Long, DayRow As Long
Dim SelDate As Date


Private Sub Worksheet_Change(ByVal Target As Range)
Dim DataSheet As Worksheet
If Not Intersect(Target, Range("AH6:AH29")) Is Nothing Then
SelDate = Range("AH5").Value 'Selected Date
YearNm = [ScYear]
'Determine if data worksheet exists
On Error Resume Next
Set DataSheet = ThisWorkbook.Sheets("" & YearNm & "")
On Error GoTo 0
If DataSheet Is Nothing Then
ThisWorkbook.Sheets.Add(After:=Sheets("Schedule")).Name = YearNm
Set DataSheet = ThisWorkbook.Sheets("" & YearNm & "")
Activate
End If
DayRow = Target.Row 'Row
DayCol = SelDate - DateSerial(YearNm, 1, 1) + 1 'Determine Column for Data Sheet
DataSheet.Cells(DayRow, DayCol).Value = Target.Value
End If
End Sub

lofghuidnb
11-11-2021, 06:19 PM
The frequent visits listed here are the easiest way to appreciate your energy fireboyand watergi (https://fireboyandwatergirl.onl)

Guillermo
05-18-2022, 05:58 AM
Hi - please kindly assist - and thank you in advance
version: Microsoft® Excel® for Microsoft 365 MSO (Version 2110 Build 16.0.14527.20234) 64-bit
the below coding runs only for column 1 on the automatically created worksheet (and any subsequent sheets (worksheets result from a named range within a dynamic calendar. – Thus, when i click/change the date or year within a dynamic calendar, data outputs to the auto created sheet labeled as the appropriate year.
The Goal and outcome: output data that is typed into "schedule" worksheet (from BOTH column AH and AI dropdown lists) into subsequent auto created sheets please note- data outputs to a column which is unlabeled -but by default/definition of coding means the top column and row refers to a named range day/date of the year corresponding to the "scheldule" worksheet created. (this means that if I type data into the schedule worksheet into drop downs in column AH and have chosen year 2020, January, 1st, then the data will appear in the 2020 worksheet 1st column which references automatically january 1, 2020. Likewise, if a chose a different year, data for the appropriate day/month will populate on a different sheet-entitled 2019, or 2021. I need the data for both columns AH and AI to appear on each subsequent sheet.


Option Explicit
Dim YearNm As Long, DayCol As Long, DayRow As Long
Dim SelDate As Date


Private Sub Worksheet_Change(ByVal Target As Range)
Dim DataSheet As Worksheet
If Not Intersect(Target, Range("AH6:AH29")) Is Nothing Then
SelDate = Range("AH5").Value 'Selected Date
YearNm = [ScYear]
'Determine if data worksheet exists
On Error Resume Next
Set DataSheet = ThisWorkbook.Sheets("" & YearNm & "")
On Error GoTo 0
If DataSheet Is Nothing Then
ThisWorkbook.Sheets.Add(After:=Sheets("Schedule")).Name = YearNm
Set DataSheet = ThisWorkbook.Sheets("" & YearNm & "")
Activate
End If
DayRow = Target.Row 'Row
DayCol = SelDate - DateSerial(YearNm, 1, 1) + 1 'Determine Column for Data Sheet
DataSheet.Cells(DayRow, DayCol).Value = Target.Value
End If
End Sub

Guillermo
05-18-2022, 05:59 AM
Hi I need that code too