Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Problem: Cells show 0 despite formulas

Dear users,

I have posted this also in microsoft.public.excel - since I really
need an expert not only in Excel but maybe also in macro programming,
I thought, I post it here, too. I was confronted with a very strange
problem. Can anybody help?

Thanks a lot

Rico

HERE WE GO:

Basically, I have 3 worksheets:

No. 1 contains all data
No. 2 contains all filtered data (macro special filter from No. 1)
No. 3 is the output, graphically optimized sheet, which has fixed
formulas to No. 2 (e.g. =Event1!A1)

Imagine, I had only these 3 sheets. Actually, I have many of them, but
there are all paired as No. 1 and 2.
No. 3 is the main sheets, which links too all No. 2's.

To update the file, I have created a macro, which compares one excel
file with the actual one. All worksheets named similarily are
replaced. The macro only looks for No. 1's and replaces all of them.
Since I have other sheets in this file, which are for another purpose,
I had to replace them by looking for the same Worksheet names.

Hence all No. 1 are replaced. No. 2 are not touched at all. Special
filter works still fine afterwards.

However, my cells in No. 3 show all 0 !!!!!

Here are two examples of formulas that both show "0":

=Event6!C2
=IF(ISNA(VLOOKUP("2006-05",Event2!A:D,4,0)),0,VLOOKUP("2006-05",Event2!
A:D,4,0))

Fascinatingly, when I click into the cell and press enter, all of a
sudden the true value appears.

I need an expert! Please help!

Here is the macro code of replacing data:

Public Sub ImportAndReplaceMISData()
Dim bStatusBarWasShown As Boolean
bStatusBarWasShown = Application.DisplayStatusBar
Application.DisplayStatusBar = True 'show status bar

' get file path of new data file
Application.StatusBar = "Choose data file..."
Dim vNewDataFilePath As Variant
vNewDataFilePath = Application.GetOpenFilename("Excel Files
(*.xls), *.xls")
If vNewDataFilePath = False Then
Application.StatusBar = False 'reset status bar
Application.DisplayStatusBar = bStatusBarWasShown
Exit Sub
End If

'keep reference to KAO workbook
Dim wbKAO As Workbook
Set wbKAO = ActiveWorkbook

'open new data file
Application.StatusBar = "Opening data file..."
Dim wbNewData As Workbook
Set wbNewData = Application.Workbooks.Open(vNewDataFilePath)
If wbNewData Is Nothing Then
Application.StatusBar = "Error opening data file!"
MsgBox "Error opening data file!", vbOKOnly Or vbCritical,
"Data File Error!"
Application.StatusBar = False 'reset status bar
Application.DisplayStatusBar = bStatusBarWasShown
Exit Sub
End If

'loop over every sheet of the new data file
' backup and replace sheets with outdated data
' add new sheets

On Error GoTo UpdateData_CopyError

Application.StatusBar = "Replacing/copying data..."
Application.DisplayAlerts = False

Dim tNow As Date
tNow = Now
Dim sBackupName As String
sBackupName = "_Backup_" & Format(tNow, "yyyymmdd_hhmmss")

Dim wsNewData As Worksheet
For Each wsNewData In wbNewData.Worksheets

'try to replace old data
Dim bReplaced As Boolean
bReplaced = False

Dim wsOldData As Worksheet
For Each wsOldData In wbKAO.Worksheets
If wsOldData.Name = wsNewData.Name Then
wsOldData.Name = wsOldData.Name & sBackupName 'backup
old data
wsNewData.Copy After:=wsOldData
wsOldData.Delete
bReplaced = True
Exit For
End If
Next

'if no old data to replace, copy it
If Not bReplaced Then
wsNewData.Copy
After:=wbKAO.Worksheets(wbKAO.Worksheets.Count)
End If
Next

'finally, close the new data file and reset Excel
UpdateData_CopyError:

wbNewData.Close

Application.DisplayAlerts = True 'reset alerts
Application.StatusBar = False 'reset status bar
Application.DisplayStatusBar = bStatusBarWasShown
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default Problem: Cells show 0 despite formulas

Hi

This is a wild stab in the dark, maybe you need to force a
recalculation. See if adding "Application.Calculate" at the end of you
macro helps any.

hth

keith

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Problem: Cells show 0 despite formulas

See your other post, too.

ricowyder wrote:

Dear users,

I have posted this also in microsoft.public.excel - since I really
need an expert not only in Excel but maybe also in macro programming,
I thought, I post it here, too. I was confronted with a very strange
problem. Can anybody help?

Thanks a lot

Rico

HERE WE GO:

Basically, I have 3 worksheets:

No. 1 contains all data
No. 2 contains all filtered data (macro special filter from No. 1)
No. 3 is the output, graphically optimized sheet, which has fixed
formulas to No. 2 (e.g. =Event1!A1)

Imagine, I had only these 3 sheets. Actually, I have many of them, but
there are all paired as No. 1 and 2.
No. 3 is the main sheets, which links too all No. 2's.

To update the file, I have created a macro, which compares one excel
file with the actual one. All worksheets named similarily are
replaced. The macro only looks for No. 1's and replaces all of them.
Since I have other sheets in this file, which are for another purpose,
I had to replace them by looking for the same Worksheet names.

Hence all No. 1 are replaced. No. 2 are not touched at all. Special
filter works still fine afterwards.

However, my cells in No. 3 show all 0 !!!!!

Here are two examples of formulas that both show "0":

=Event6!C2
=IF(ISNA(VLOOKUP("2006-05",Event2!A:D,4,0)),0,VLOOKUP("2006-05",Event2!
A:D,4,0))

Fascinatingly, when I click into the cell and press enter, all of a
sudden the true value appears.

I need an expert! Please help!

Here is the macro code of replacing data:

Public Sub ImportAndReplaceMISData()
Dim bStatusBarWasShown As Boolean
bStatusBarWasShown = Application.DisplayStatusBar
Application.DisplayStatusBar = True 'show status bar

' get file path of new data file
Application.StatusBar = "Choose data file..."
Dim vNewDataFilePath As Variant
vNewDataFilePath = Application.GetOpenFilename("Excel Files
(*.xls), *.xls")
If vNewDataFilePath = False Then
Application.StatusBar = False 'reset status bar
Application.DisplayStatusBar = bStatusBarWasShown
Exit Sub
End If

'keep reference to KAO workbook
Dim wbKAO As Workbook
Set wbKAO = ActiveWorkbook

'open new data file
Application.StatusBar = "Opening data file..."
Dim wbNewData As Workbook
Set wbNewData = Application.Workbooks.Open(vNewDataFilePath)
If wbNewData Is Nothing Then
Application.StatusBar = "Error opening data file!"
MsgBox "Error opening data file!", vbOKOnly Or vbCritical,
"Data File Error!"
Application.StatusBar = False 'reset status bar
Application.DisplayStatusBar = bStatusBarWasShown
Exit Sub
End If

'loop over every sheet of the new data file
' backup and replace sheets with outdated data
' add new sheets

On Error GoTo UpdateData_CopyError

Application.StatusBar = "Replacing/copying data..."
Application.DisplayAlerts = False

Dim tNow As Date
tNow = Now
Dim sBackupName As String
sBackupName = "_Backup_" & Format(tNow, "yyyymmdd_hhmmss")

Dim wsNewData As Worksheet
For Each wsNewData In wbNewData.Worksheets

'try to replace old data
Dim bReplaced As Boolean
bReplaced = False

Dim wsOldData As Worksheet
For Each wsOldData In wbKAO.Worksheets
If wsOldData.Name = wsNewData.Name Then
wsOldData.Name = wsOldData.Name & sBackupName 'backup
old data
wsNewData.Copy After:=wsOldData
wsOldData.Delete
bReplaced = True
Exit For
End If
Next

'if no old data to replace, copy it
If Not bReplaced Then
wsNewData.Copy
After:=wbKAO.Worksheets(wbKAO.Worksheets.Count)
End If
Next

'finally, close the new data file and reset Excel
UpdateData_CopyError:

wbNewData.Close

Application.DisplayAlerts = True 'reset alerts
Application.StatusBar = False 'reset status bar
Application.DisplayStatusBar = bStatusBarWasShown
End Sub


--

Dave Peterson
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
Problem with copied formulas into cells AdamMiles47 New Users to Excel 1 October 5th 10 04:48 AM
Show cells with formulas without permanently changing the cells DoctorG Excel Programming 10 July 19th 06 12:43 PM
problem getting formulas in cells that user adresses.. Pierre via OfficeKB.com[_2_] Excel Programming 1 December 16th 05 06:29 PM
can you show formulas in selected cells only of a worksheet? covenantdanes Excel Programming 3 June 5th 05 06:09 AM
How do you show formulas in certain cells only (not the whole she. andy Excel Worksheet Functions 2 February 16th 05 07:05 PM


All times are GMT +1. The time now is 12:56 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"