Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Retrieve Formula Result when Saving

I want to be able to take the last value in a column on Sheet 2 and display
it in another spreadsheet(Sheet 1) in cell A1 whenever someone saves the
workbook. The cell I want to copy contains a formula which displays the
calculated result and if a value isn't calculated the cells display nothing.
I would like to only take the last cell in column B that has a value.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Retrieve Formula Result when Saving

Try putting something like this in the ThisWorkbook module:

Option Explicit

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim oneCell As Range

Set oneCell = Worksheets("Sheet2").Cells(Rows.Count,
"B").End(xlUp)

Do While oneCell.Row 1'It assumes that your value always will be
in a row that's greater than 1
If oneCell.Value = vbNullString Then'Checks if the non empty
cell actually displays any value
Set oneCell = oneCell(0, 1)'Goes one row up
Else: Exit Do'there was value - that's your cell
End If
Loop
Worksheets("Sheet1").Range("A1").Value = oneCell.Value'put the
value into your target cell

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Retrieve Formula Result when Saving

AB-

Thanks for the suggestion, but I keep getting a runtime error:

Run-time error '13'
Type mismatch

When I debug it takes me to this line:

If oneCell.Value = vbNullString Then 'Checks if the non empty cell actually
displays any value

"AB" wrote:

Try putting something like this in the ThisWorkbook module:

Option Explicit

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim oneCell As Range

Set oneCell = Worksheets("Sheet2").Cells(Rows.Count,
"B").End(xlUp)

Do While oneCell.Row 1'It assumes that your value always will be
in a row that's greater than 1
If oneCell.Value = vbNullString Then'Checks if the non empty
cell actually displays any value
Set oneCell = oneCell(0, 1)'Goes one row up
Else: Exit Do'there was value - that's your cell
End If
Loop
Worksheets("Sheet1").Range("A1").Value = oneCell.Value'put the
value into your target cell

End Sub
.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Retrieve Formula Result when Saving

What's the value in that cell? (for you to know which cell has the
faulty result try in the immediate window this (once the row gets
highlighted in yellow, the error fires and you click on debug)
?onecell.address (and then hit enter) - it will give you the address
of the cell that's wrong.
There would be an error, I guess - i.e., the cell value isn't blank
and isn't a number and isn't a text but it's something like
!DIVO
#NA
or any other similar error.
If you fix the formula not to show errors, it should be fine.
In the meantime if the onecell value isn't error - post back.
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
I closed an excel file without saving the changes. Can I retrieve cliffordof fremontca Excel Discussion (Misc queries) 1 April 9th 10 12:16 AM
Saving A One Off IF Result Rebecca[_4_] Excel Worksheet Functions 3 February 15th 09 07:31 PM
Retrieve result of query from Access oscar.c.marin[_2_] Excel Programming 3 November 12th 08 12:34 PM
Advanced formula - Return result & Show Cell Reference of result Irv Excel Worksheet Functions 7 May 6th 06 03:36 AM
How can I retrieve a file that was closed without saving? Digvid99 Excel Discussion (Misc queries) 1 February 24th 05 08:59 PM


All times are GMT +1. The time now is 06:08 PM.

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

About Us

"It's about Microsoft Excel"