Technology Get the latest on technology, electronics and software…

Excel question

Thread Tools
 
Old 06-30-2007 | 10:33 AM
  #1  
hornyleprechaun's Avatar
Thread Starter
Bent = #1
 
Joined: Dec 2001
Posts: 13,473
Likes: 25
From: Marietta, GA
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!
Old 06-30-2007 | 10:37 AM
  #2  
elessar's Avatar
Return of the Ring
 
Joined: Feb 2004
Posts: 5,327
Likes: 39
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

Last edited by elessar; 06-30-2007 at 10:42 AM.
Old 06-30-2007 | 10:44 AM
  #3  
hornyleprechaun's Avatar
Thread Starter
Bent = #1
 
Joined: Dec 2001
Posts: 13,473
Likes: 25
From: Marietta, GA
I get a "Type mismatch" error when I try to do that..
Old 06-30-2007 | 10:47 AM
  #4  
hornyleprechaun's Avatar
Thread Starter
Bent = #1
 
Joined: Dec 2001
Posts: 13,473
Likes: 25
From: Marietta, GA
BUT I didn't put parentheses around the first line, and just the bottom 2 lines and it worked! Thanks and repped!
Old 06-30-2007 | 10:49 AM
  #5  
hornyleprechaun's Avatar
Thread Starter
Bent = #1
 
Joined: Dec 2001
Posts: 13,473
Likes: 25
From: Marietta, GA
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
Old 06-30-2007 | 10:54 AM
  #6  
elessar's Avatar
Return of the Ring
 
Joined: Feb 2004
Posts: 5,327
Likes: 39
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
Old 06-30-2007 | 10:56 AM
  #7  
hornyleprechaun's Avatar
Thread Starter
Bent = #1
 
Joined: Dec 2001
Posts: 13,473
Likes: 25
From: Marietta, GA
Same type mismatch error
Old 06-30-2007 | 10:59 AM
  #8  
hornyleprechaun's Avatar
Thread Starter
Bent = #1
 
Joined: Dec 2001
Posts: 13,473
Likes: 25
From: Marietta, GA
This could be my problem..

http://support.microsoft.com/kb/821292
Old 06-30-2007 | 11:09 AM
  #9  
hornyleprechaun's Avatar
Thread Starter
Bent = #1
 
Joined: Dec 2001
Posts: 13,473
Likes: 25
From: Marietta, GA
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!
Old 06-30-2007 | 11:19 AM
  #10  
hornyleprechaun's Avatar
Thread Starter
Bent = #1
 
Joined: Dec 2001
Posts: 13,473
Likes: 25
From: Marietta, GA
Update didn't work
Old 06-30-2007 | 11:21 AM
  #11  
elessar's Avatar
Return of the Ring
 
Joined: Feb 2004
Posts: 5,327
Likes: 39
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
Old 06-30-2007 | 11:41 AM
  #12  
hornyleprechaun's Avatar
Thread Starter
Bent = #1
 
Joined: Dec 2001
Posts: 13,473
Likes: 25
From: Marietta, GA
Yup worked like a charm.. thanks again! This concludes the hornyleprechaun and elessar excel help thread
Old 06-30-2007 | 11:45 AM
  #13  
kona's Avatar
Racer
 
Joined: Nov 2003
Posts: 376
Likes: 0
From: Pasadena, CA
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
Old 06-30-2007 | 12:12 PM
  #14  
sonnyg80's Avatar
...
 
Joined: Mar 2006
Posts: 14,398
Likes: 0
Originally Posted by hornyleprechaun
Yup worked like a charm.. thanks again! This concludes the hornyleprechaun and elessar excel help thread
stop doing work on your birthday!!
Old 06-30-2007 | 01:27 PM
  #15  
elessar's Avatar
Return of the Ring
 
Joined: Feb 2004
Posts: 5,327
Likes: 39
Originally Posted by hornyleprechaun
Yup worked like a charm.. thanks again! This concludes the hornyleprechaun and elessar excel help thread
Awesome! Now like sonny said, get the hell out there & start celebrating your birthday, dude!!
Old 06-30-2007 | 01:34 PM
  #16  
hornyleprechaun's Avatar
Thread Starter
Bent = #1
 
Joined: Dec 2001
Posts: 13,473
Likes: 25
From: Marietta, GA
I can't yet! My g/f is getting her hair highlighted, so whenever she is done I can leave and start boozing
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
navtool.com
3G MDX (2014-2020)
32
01-20-2016 11:43 AM
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



Quick Reply: Excel question



All times are GMT -5. The time now is 10:15 PM.