Hi:
SheetPlan should be worksheets("Plan")
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
If SheetPlan.Range("A1") = DateSerial(2007, 3, 5) Then
' XXXXXXXX
Worksheets("Plan").Range("B43") =
Worksheets("Summary").Range ("E14")
End If
End Sub
for multiple dates try an if statement:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
dim dc as date ' hold the date from the worksheet
dim sCellAddress as string ' hold the address of the cell
dc=worksheets("Plan").Range("A1")
If dc= DateSerial(2007, 3, 6) Then
sCellAddress="B43"
elseif dc= DateSerial(2007, 3, 7) Then
sCellAddress="B44"
elseif dc= DateSerial(2007, 3, 8) Then
sCellAddress="B45"
elseif dc= DateSerial(2007, 4, 1) Then
sCellAddress="B46"
End If
Worksheets("Plan").Range(sCellAddress) =
Worksheets("Summary").Range ("F14")
End Sub
But I would rather use a lookup table in the workbook say on sheet called
'lookup' with vba where in your lookup table you have
date destination_cell destination_worksheet
=date(2007,3,6) B43 Plan
=date(2007,3,7) B44 Plan
=date(2007,3,8) B45 Plan
=date(2007,4,1) B46 Plan
you can then do:
Const csz_wsLookupName As String = "lookup"
Const csz_rLookup As String = "A:C"
Const ci_ColCell As Long = 2
Const ci_ColSheet As Long = 3
'Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
' Cancel As Boolean)
Private Sub Workbook_BeforeSave( _
ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim dc As Date ' hold the date from the worksheet
Dim sz_CellAddress As String ' hold the address of the cell
Dim sz_Sheet As String ' hold sheet name
Dim a ' answer
dc = Worksheets("Plan").Range("A1")
a = Application.VLookup(CLng(dc), _
Worksheets(csz_wsLookupName).Range(csz_rLookup), _
ci_ColCell, False)
If Not (IsError(a)) Then
sz_CellAddress = a
a = Application.WorksheetFunction.VLookup(CLng(dc), _
Worksheets(csz_wsLookupName).Range(csz_rLookup), _
ci_ColSheet, False)
sz_Sheet = a
Worksheets(sz_Sheet).Range(sz_CellAddress) = _
Worksheets("Summary").Range("F14")
End If
End Sub
--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.
- Show quoted text -
Thank you Martin. The If Stmt worked great.
One more question...
How do I reference a cell that is part of a pivot table instead of
using this...Worksheets("Summary").Range("D14")
The issue is that the data may change positions, depending on the
amount of data, so referencing a value of a pivot table would be
better. This is my pivot table location that is currently the same as
D14...
=GETPIVOTDATA("mnemonic",Summary!$A$2,"status","NOK")
Below is what I have so far...
Many Thanks!
Meg
Sub Aut

pen()
Dim dc As Date ' hold the date from the worksheet
Dim sCellAddress As String ' hold the address of the cell
dc = Worksheets("Plan").Range("A1")
If dc = DateSerial(2007, 3, 5) Then
sCellAddress = "B42"
ElseIf dc = DateSerial(2007, 3, 6) Then
sCellAddress = "C42"
ElseIf dc = DateSerial(2007, 3, 7) Then
sCellAddress = "D42"
ElseIf dc = DateSerial(2007, 3, 8) Then
sCellAddress = "E42"
ElseIf dc = DateSerial(2007, 3, 9) Then
sCellAddress = "F42"
ElseIf dc = DateSerial(2007, 3, 10) Then
sCellAddress = "G42"
End If
Worksheets("Plan").Range(sCellAddress) =
Worksheets("Summary").Range("D14")
End Sub