Excel question
#1
Excel question
Ok I am trying to make a little macro that will hide cells that contain "0" or "" (nothing). The following code below works when I just do it for one cell:
If Cells(13, 3) = "" Or Cells(13, 3) = "0" Then
Rows("12:13").Hidden = True
End If
But the following code below does not work when there is an actual # in cell C24 and C25 & C26 are empty, it will still hide the cells. This happens when C25 has a # in it and C24 & C26 are empty. BUT when C24 & C25 are empty, and C26 has a # in it, the cells won't be made hidden...
If Cells(24, 3) = "" Or Cells(24, 3) = "0" & _
Cells(25, 3) = "" Or Cells(25, 3) = "0" & _
Cells(26, 3) = "" Or Cells(26, 3) = "0" Then
Rows("23:26").Hidden = True
Else
Rows("23:26").Hidden = False
End If
And I added the "Else" this morning and prior to that the same results occurred. If anyone can help I would greatly appreciate it! Thanks!
If Cells(13, 3) = "" Or Cells(13, 3) = "0" Then
Rows("12:13").Hidden = True
End If
But the following code below does not work when there is an actual # in cell C24 and C25 & C26 are empty, it will still hide the cells. This happens when C25 has a # in it and C24 & C26 are empty. BUT when C24 & C25 are empty, and C26 has a # in it, the cells won't be made hidden...
If Cells(24, 3) = "" Or Cells(24, 3) = "0" & _
Cells(25, 3) = "" Or Cells(25, 3) = "0" & _
Cells(26, 3) = "" Or Cells(26, 3) = "0" Then
Rows("23:26").Hidden = True
Else
Rows("23:26").Hidden = False
End If
And I added the "Else" this morning and prior to that the same results occurred. If anyone can help I would greatly appreciate it! Thanks!
#2
I'm not an Excel expert, but I think your ANDs and ORs might be getting "mixed up" due to operator precedence rules. Will it let you put parentheses around the OR conditions, like this?
If (Cells(24, 3) = "" Or Cells(24, 3) = "0") & _
(Cells(25, 3) = "" Or Cells(25, 3) = "0") & _
(Cells(26, 3) = "" Or Cells(26, 3) = "0") Then
Rows("23:26").Hidden = True
Else
Rows("23:26").Hidden = False
End If
If (Cells(24, 3) = "" Or Cells(24, 3) = "0") & _
(Cells(25, 3) = "" Or Cells(25, 3) = "0") & _
(Cells(26, 3) = "" Or Cells(26, 3) = "0") Then
Rows("23:26").Hidden = True
Else
Rows("23:26").Hidden = False
End If
Last edited by elessar; 06-30-2007 at 10:42 AM.
#5
O no.. but now when all 3 are empty it won't hide the cells...
If Cells(24, 3) = "" Or Cells(24, 3) = "0" & _
(Cells(25, 3) = "" Or Cells(25, 3) = "0") & _
(Cells(26, 3) = "" Or Cells(26, 3) = "0") Then
Rows("23:26").Hidden = True
Else
Rows("23:26").Hidden = False
End If
If Cells(24, 3) = "" Or Cells(24, 3) = "0" & _
(Cells(25, 3) = "" Or Cells(25, 3) = "0") & _
(Cells(26, 3) = "" Or Cells(26, 3) = "0") Then
Rows("23:26").Hidden = True
Else
Rows("23:26").Hidden = False
End If
#6
Hmmm... dunno why it won't let you put them around the 1st line... Have you tried this?
If ((Cells(24, 3) = "" Or Cells(24, 3) = "0") & _
(Cells(25, 3) = "" Or Cells(25, 3) = "0") & _
(Cells(26, 3) = "" Or Cells(26, 3) = "0")) Then
Rows("23:26").Hidden = True
Else
Rows("23:26").Hidden = False
End If
If ((Cells(24, 3) = "" Or Cells(24, 3) = "0") & _
(Cells(25, 3) = "" Or Cells(25, 3) = "0") & _
(Cells(26, 3) = "" Or Cells(26, 3) = "0")) Then
Rows("23:26").Hidden = True
Else
Rows("23:26").Hidden = False
End If
Trending Topics
#8
#9
I am going to try the update, but this is for work, so even if it works here it really has to work at work. So if anyone has a solution besides the update (if that even works) then I'd appreciate it!
#11
Maybe you need to be using "AND" instead of "&"? From my Excel Help, it looks like "&" is a string concatenation operator, and "AND" is a comparison operator. Worth a shot, right?
If ((Cells(24, 3) = "" Or Cells(24, 3) = "0") AND _
(Cells(25, 3) = "" Or Cells(25, 3) = "0") AND _
(Cells(26, 3) = "" Or Cells(26, 3) = "0")) Then
Rows("23:26").Hidden = True
Else
Rows("23:26").Hidden = False
End If
If ((Cells(24, 3) = "" Or Cells(24, 3) = "0") AND _
(Cells(25, 3) = "" Or Cells(25, 3) = "0") AND _
(Cells(26, 3) = "" Or Cells(26, 3) = "0")) Then
Rows("23:26").Hidden = True
Else
Rows("23:26").Hidden = False
End If
#13
This worked for me.
Sub Macro1()
If Cells(24, 3) = vbEmpty Or Cells(24, 3) = "0" & _
Cells(25, 3) = vbEmpty Or Cells(25, 3) = "0" & _
Cells(26, 3) = vbEmpty Or Cells(26, 3) = "0" Then
Rows("23:26").Hidden = True
Else
Rows("23:26").Hidden = False
End If
End Sub
Sub Macro1()
If Cells(24, 3) = vbEmpty Or Cells(24, 3) = "0" & _
Cells(25, 3) = vbEmpty Or Cells(25, 3) = "0" & _
Cells(26, 3) = vbEmpty Or Cells(26, 3) = "0" Then
Rows("23:26").Hidden = True
Else
Rows("23:26").Hidden = False
End If
End Sub
#15
Originally Posted by hornyleprechaun
Yup worked like a charm.. thanks again! This concludes the hornyleprechaun and elessar excel help thread
Thread
Thread Starter
Forum
Replies
Last Post
navtool.com
5G TLX Audio, Bluetooth, Electronics & Navigation
31
11-16-2015 08:30 PM
navtool.com
1G RDX Audio, Bluetooth, Electronics & Navigation
1
09-25-2015 05:15 PM
rboller
3G TL Audio, Bluetooth, Electronics & Navigation
0
09-23-2015 02:49 PM