Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Cell reference in Workbook_BeforeSave macro

I'm writing a macro to update a notification cell (B10) to indicate when the
worksheet has changed. The following code works:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim CurRow As Long: Dim CurColumn As Long
CurRow = Target.Row
CurColumn = Target.Column
Range("B10").Select
ActiveCell.FormulaR1C1 = "As of " & Format(Now(), "general date")
Cells(CurRow, CurColumn).Select
End Sub

After a cell is changed, this code updates the notification cell and then
returns to the cell just changed. This is a workSHEET function, so it fires
after each change to any cell on the sheet. What I'd really like to do is
update the notification only when the user saves the changes to the workbook
(Save, or Close/Save). I found the following workBOOK function that seems
appropriate:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

If I paste in the code above, I get an "Object Required" error on the line
"CurRow = Target.Row", probably because "Target" is not defined in the Sub
header. If I take out the lines relating to CurRow and CurColumn, the macro
works - it updates the notification cell, but leaves that cell selected.
This may be OK, but is there a way I can return the user to the cell he or
she was in? (Let's say the user makes a change, saves, and wants to
continue working in the sheet.) How can I pass the cell or range to this
macro? Is there a different event I should be using?

Thanks,
Bob



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Cell reference in Workbook_BeforeSave macro

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim CurCell As Range
Set CurCell = Activecell
Range("B10").Select
ActiveCell.FormulaR1C1 = "As of " & Format(Now(), "general date")
CurCell.Select
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Bob" wrote in message
...
I'm writing a macro to update a notification cell (B10) to indicate when

the
worksheet has changed. The following code works:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim CurRow As Long: Dim CurColumn As Long
CurRow = Target.Row
CurColumn = Target.Column
Range("B10").Select
ActiveCell.FormulaR1C1 = "As of " & Format(Now(), "general date")
Cells(CurRow, CurColumn).Select
End Sub

After a cell is changed, this code updates the notification cell and then
returns to the cell just changed. This is a workSHEET function, so it

fires
after each change to any cell on the sheet. What I'd really like to do is
update the notification only when the user saves the changes to the

workbook
(Save, or Close/Save). I found the following workBOOK function that seems
appropriate:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

If I paste in the code above, I get an "Object Required" error on the line
"CurRow = Target.Row", probably because "Target" is not defined in the Sub
header. If I take out the lines relating to CurRow and CurColumn, the

macro
works - it updates the notification cell, but leaves that cell selected.
This may be OK, but is there a way I can return the user to the cell he or
she was in? (Let's say the user makes a change, saves, and wants to
continue working in the sheet.) How can I pass the cell or range to this
macro? Is there a different event I should be using?

Thanks,
Bob





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Cell reference in Workbook_BeforeSave macro

Hi, Bob,

Thanks for the very quick reply. Alls I've got to say is, "Duuuhhh...".

Well, that and, "Thanks, again!"

Bob

"Bob Phillips" wrote in message
...
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim CurCell As Range
Set CurCell = Activecell
Range("B10").Select
ActiveCell.FormulaR1C1 = "As of " & Format(Now(), "general date")
CurCell.Select
End Sub

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Bob" wrote in message
...
I'm writing a macro to update a notification cell (B10) to indicate when

the
worksheet has changed. The following code works:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim CurRow As Long: Dim CurColumn As Long
CurRow = Target.Row
CurColumn = Target.Column
Range("B10").Select
ActiveCell.FormulaR1C1 = "As of " & Format(Now(), "general date")
Cells(CurRow, CurColumn).Select
End Sub

After a cell is changed, this code updates the notification cell and then
returns to the cell just changed. This is a workSHEET function, so it

fires
after each change to any cell on the sheet. What I'd really like to do
is
update the notification only when the user saves the changes to the

workbook
(Save, or Close/Save). I found the following workBOOK function that
seems
appropriate:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

If I paste in the code above, I get an "Object Required" error on the
line
"CurRow = Target.Row", probably because "Target" is not defined in the
Sub
header. If I take out the lines relating to CurRow and CurColumn, the

macro
works - it updates the notification cell, but leaves that cell selected.
This may be OK, but is there a way I can return the user to the cell he
or
she was in? (Let's say the user makes a change, saves, and wants to
continue working in the sheet.) How can I pass the cell or range to this
macro? Is there a different event I should be using?

Thanks,
Bob







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro using a cell reference Jason Falzon[_2_] Excel Discussion (Misc queries) 3 March 24th 10 04:16 PM
is it possible to run a macro using a cell reference? JasonK Excel Programming 3 March 18th 06 12:38 AM
cell reference using macro Alex Martinez Excel Programming 2 September 15th 05 09:06 AM
Macro cell reference help justaguyfromky Excel Programming 9 January 8th 05 05:43 PM
Cell Reference in a Macro Tim Excel Programming 1 April 28th 04 06:31 PM


All times are GMT +1. The time now is 04:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"