Jon von der Heyden
MrExcel MVP, Moderator
- Joined
- Apr 6, 2004
- Messages
- 10,912
- Office Version
- 365
- Platform
- Windows
Hi,
I am trying to return a date using Calendar Control.
I have Calendar1 within frmCalendar.
Code for Calendar1
I then have a command button located within worksheets to run another macro. The macro that it calls is call_data:
How do I link iDate in Calendar1 to iDate in call_data?
Best regards
Jon
I am trying to return a date using Calendar Control.
I have Calendar1 within frmCalendar.
Code for Calendar1
Code:
Private Sub Calendar1_Click()
Dim iDate
iDate = Calendar1.Value
Unload Me
End Sub
I then have a command button located within worksheets to run another macro. The macro that it calls is call_data:
Code:
Sub call_data()
Dim ws As Worksheet
Dim lRow, fRow, Lines As Long
Dim iDate As Date
Application.ScreenUpdating = False
Set ws = ActiveSheet
lRow = Cells(Rows.Count, 2).End(xlUp).Row + 1
cmdDatabaseOpen_Click
Lines = Cells(Rows.Count, 1).End(xlUp).Row - 1
Cells(2, 1).Resize(Lines, 2).Copy _
ws.Cells(lRow, 2)
ActiveWorkbook.Close
frmCalendar.Show
iDate = Calendar1.Value
fRow = lRow
lRow = fRow + Lines - 1
For i = fRow To lRow
On Error Resume Next
Cells(i, 5) = Application.WorksheetFunction.VLookup(Cells(i, 2), Range("PC_Map"), 8, 0)
Cells(i, 6) = Application.WorksheetFunction.VLookup(Cells(i, 2), Range("PC_Map"), 3, 0)
Cells(i, 7) = Application.WorksheetFunction.VLookup(Cells(i, 2), Range("PC_Map"), 10, 0)
Cells(i, 8) = Application.WorksheetFunction.VLookup(Cells(i, 2), Range("PC_Map"), 6, 0)
Cells(i, 9) = Application.WorksheetFunction.VLookup(Cells(i, 2), Range("PC_Map"), 13, 0)
Cells(i, 11) = iDate
Cells(i, 13) = Application.WorksheetFunction.SumIf(Range("I5:I" & i), Range("I" & i), Range("C5:C" & i))
With Cells(i, 15)
.Formula = "=SUMPRODUCT(--(M" & i & ">" & ws.Name & "_Bands),(M" & i & "-" & ws.Name & "_Bands)," & ws.Name & "_Diff)"
.Value = .Value
End With
Cells(i, 14) = Cells(i, 15) - Application.WorksheetFunction.SumIf(Range("I5:I" & i - 1), Range("I" & i), Range("N5:N" & i - 1))
Next
Application.ScreenUpdating = True
End Sub
How do I link iDate in Calendar1 to iDate in call_data?
Best regards
Jon