zero appears in the Msg box

KlausW

Active Member
Joined
Sep 9, 2020
Messages
449
Office Version
  1. 2016
Platform
  1. Windows
Hi everyone In an Msg box, some information from some cells has, see the VBA code.
This works well, but when the cells are empty a zero appears in the Msg box see image, can I hide them?

Any help will be appreciated

Best regards Klaus W

VBA Code:
Sub Afrundetrektangel1_Klik()

If Range("ai52") = 0 Then Range("ai75") = ""

MsgBox Range("Ai52") & vbNewLine & Range("Ai53") & vbNewLine & Range("Ai54") & vbNewLine & Range("Ai55") & vbNewLine & Range("Ai56") & vbNewLine & Range("Ai57") & vbNewLine & Range("Ai58") & vbNewLine & Range("Ai59") & vbNewLine & Range("Ai60") & vbNewLine & Range("Ai61") & vbNewLine & Range("Ai62") & vbNewLine & Range("Ai63") & vbNewLine & Range("Ai64") & vbNewLine & Range("Ai65") & vbNewLine & Range("Ai66") & vbNewLine & Range("Ai67") & vbNewLine & Range("Ai68") & vbNewLine & Range("Ai69") & vbNewLine & Range("Ai70") & vbNewLine & Range("Ai71") & vbNewLine & Range("Ai72") & vbNewLine & Range("Ai73") & vbNewLine & Range("Ai74") & vbNewLine & Range("Ai75"), , "Symbol oversigt tjeneste-frihed"

Sheets(Format(Now, "mmmm")).Select 

End Sub
 

Attachments

  • Pic1.PNG
    Pic1.PNG
    13.3 KB · Views: 9

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
If the cells are empty they do not show as 0 for me with your code. Are you sure that they do not contain 0 values, perhaps hidden by formatting?

Could we have some of your sample data with XL2BB for testing?
 
Upvote 0
If the cells are empty they do not show as 0 for me with your code. Are you sure that they do not contain 0 values, perhaps hidden by formatting?

Could we have some of your sample data with XL2BB for testing?
Hi Peter, yes the cells contain formulas. Can it help with understanding? Klaus W
 
Last edited by a moderator:
Upvote 0
.. and do those formulas return zero in what you are calling 'empty' cells?
Could you post one of those formulas?


This would help even more ..
This is the formula in the celles =April!AI55
 
Upvote 0
Hi Peter
Is it like this


Cell Formulas
RangeFormula
A5A5=PROPER(TEXT(A2,"mmmm")) & " " & YEAR(A2)
C6C6=IFERROR(INDEX(Navn!$A$3:$E$17,MATCH($N$6,Navn!$D$3:$D$17,0),1),"")
F6F6=IFERROR(VLOOKUP($C$6,Navn!$A$3:$F$16,2,FALSE),"")
I6I6=IFERROR(VLOOKUP($C$6,Navn!$A$3:$F$16,3,FALSE),"")
N6N6=Navn!$C$1
AC6AC6=IFERROR(VLOOKUP($C$6,Navn!$A$3:$F$16,5,FALSE),"")
AI6AI6=PROPER(C4)&" "&N6
C7:AD7C7=IF(C10="Mandag",WEEKNUM(C9,1),"")
C8:H8C8=HelligdagsNavn(C9,0,0)
C10:AG10C10=PROPER(TEXT(C9,"dddd"))
C11:AG11C11=DAY(C9)
AH51AH51=Navn!AH10
A52A52=SUM(A53:A59)
AI51:AI75AI51='D:\[BM.xlsm]April'!AI52
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C10:AG11Expression=MÅNED(C$9)<>MÅNED($A$2)textNO
11:11,A10:AG10,AI10:XFD10,AH51Expression=A$3textYES
C10:AG11Expression=OG(UGEDAG(C$9;2)>5;MÅNED(C$9)=MÅNED($A$2))textNO
 
Upvote 0
Thanks for the XL2BB sample data - much more useful. :)

Unfortunately, it does not directly resolve why you are getting those 0 values. Having copied your data (not formulas since I do not have the linked files or worksheets) to my test worksheet and running your code from post 1, this is what I get.

1725233378158.png


However, I think there may be a clue or two
... and do those formulas return zero in what you are calling 'empty' cells?
You did not answer that question of mine, but I think the answer may be 'yes' and that the cells are formatted to hide zero values. The reason that I am guessing that is that in your mini sheet above, cell A52 contains the formula.
=SUM(A53:A59)
Such a formula must return either a number or an error, it cannot return a null string "". Since I cannot see any values or formulas in A53:A59 I assume that the sum formula is returning a 0, hidden by formatting. I am guessing then the same sort of thing might be happening in col AI.

Another thing that suggests the same is this line in your code ..
Rich (BB code):
If Range("ai52") = 0 Then Range("ai75") = ""
.. indicating the possibility of a 0 in col AI, not ""

Based on the above observations, see what this code does

VBA Code:
Sub Afrundetrektangel1_Klik_v2()
  If Range("AI52") = 0 Then Range("AI75") = ""
  MsgBox Replace(Join(Filter(Split("|" & Join(Application.Transpose(Range("AI52:AI75").Value), "|#|") & "|", "#"), "|0|", False), vbLf), "|", ""), , "Symbol oversigt tjeneste-frihed"
  Sheets(Format(Date, "mmmm")).Select
End Sub
 
Upvote 0
Solution
Thanks for the XL2BB sample data - much more useful. :)

Unfortunately, it does not directly resolve why you are getting those 0 values. Having copied your data (not formulas since I do not have the linked files or worksheets) to my test worksheet and running your code from post 1, this is what I get.

View attachment 116239

However, I think there may be a clue or two

You did not answer that question of mine, but I think the answer may be 'yes' and that the cells are formatted to hide zero values. The reason that I am guessing that is that in your mini sheet above, cell A52 contains the formula.
=SUM(A53:A59)
Such a formula must return either a number or an error, it cannot return a null string "". Since I cannot see any values or formulas in A53:A59 I assume that the sum formula is returning a 0, hidden by formatting. I am guessing then the same sort of thing might be happening in col AI.

Another thing that suggests the same is this line in your code ..
Rich (BB code):
If Range("ai52") = 0 Then Range("ai75") = ""
.. indicating the possibility of a 0 in col AI, not ""

Based on the above observations, see what this code does

VBA Code:
Sub Afrundetrektangel1_Klik_v2()
  If Range("AI52") = 0 Then Range("AI75") = ""
  MsgBox Replace(Join(Filter(Split("|" & Join(Application.Transpose(Range("AI52:AI75").Value), "|#|") & "|", "#"), "|0|", False), vbLf), "|", ""), , "Symbol oversigt tjeneste-frihed"
  Sheets(Format(Date, "mmmm")).Select
End Sub
Good morning Peter_SSs
Thank you very much as it should be.
Have a nice day, many greetings from Denmark, Klaus W
 
Upvote 0
I could be wrong but this seems to give the same result.

VBA Code:
Sub Afrundetrektangel1_Klik_v2()
  If Range("AI52") = 0 Then Range("AI75") = ""
  MsgBox Join(Filter(Application.Transpose(Range("AI52:AI75").Value), 0, False), vbLf), , "Symbol oversigt tjeneste-frihed"
  Sheets(Format(Date, "mmmm")).Select
End Sub
 
Upvote 0
I could be wrong but this seems to give the same result.

VBA Code:
Sub Afrundetrektangel1_Klik_v2()
  If Range("AI52") = 0 Then Range("AI75") = ""
  MsgBox Join(Filter(Application.Transpose(Range("AI52:AI75").Value), 0, False), vbLf), , "Symbol oversigt tjeneste-frihed"
  Sheets(Format(Date, "mmmm")).Select
End Sub
Too risky I would say, Alex. vba Filter is a "contains" (or "does not contain") filter.
Example: If AI61 was "P for AFS. P 70" instead of "P for AFS. P 17" then it would be omitted from the message box.

Good morning Peter_SSs
Thank you very much as it should be.
Have a nice day, many greetings from Denmark, Klaus W
You're welcome. Thanks for the follow-up. I think we would be going on for ages trying to solve the issue without the XL2BB sample so please consider always giving some representative sample data and the expected results with XL2BB in any new threads you start. It will generally get you faster and better responses. :)
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top