If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Range Problem in VB Editor

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-12-08, 18:22
MillB MillB is offline
Registered User
 
Join Date: Dec 2006
Posts: 39
Range Problem in VB Editor

For some reason I get a runtime error when I specify a whole range, but if I do the cells individually it works. What I need is to be able set the
RANGE ("C13:N13" = "" Then

Does anyone know if I'm overlooking something, or could provide a possible solution?

See attached Screenshots for visual. Notice where the code breaks...that's where I'm stumped.

Thanks....


MillB
Attached Thumbnails
Range Problem in VB Editor-screenshot1.png   Range Problem in VB Editor-screenshot2.png   Range Problem in VB Editor-screenshot3.png  
Reply With Quote
  #2 (permalink)  
Old 05-14-08, 08:41
MikeTheBike MikeTheBike is offline
Registered User
 
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
Hi

Yes it would seem this doesn't work with multi cell ranges.

I would suggest a little function (especialy if you use this more than once in your code) thus

Code:
Function RangeIsBlank(ByRef ThisRange As Range) As Boolean
    Dim cel As Range
    RangeIsBlank = True
    For Each cel In ThisRange
        If cel <> "" Then RangeIsBlank = False
    Next cel
End Function
Used like this

Code:
Sub test()
    If RangeIsBlank(Range("C13:N13")) Then
         MsgBox "Range is Blank"
         'etc
         'etc
    End If
End Sub
HTH


MTB
Reply With Quote
  #3 (permalink)  
Old 05-25-08, 14:52
norie norie is offline
Registered User
 
Join Date: Mar 2006
Posts: 163
MillB

You can't compare a single value to multiple values like that.
Reply With Quote
  #4 (permalink)  
Old 05-27-08, 14:44
stuschmied stuschmied is offline
Registered User
 
Join Date: May 2008
Location: Raleigh, NC
Posts: 151
It can't be this simple...

Hi,

I couldn't make out your screenshots so I tried this simple code and it worked fine for me. I can't tell by your post where you have the final paren but make sure its before the equal sign.


Private Sub TestRange()

Range("C13:N13") = "Test"
Range("C13:N13") = ""

End Sub

Good luck, Stu
__________________
--If its free, take it for what its worth!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On