Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Problems with If "range" is nothing then

This is the part of the macro and it doesn't work the way I intended
it to do.

If FromCell Is Nothing _
Or FromCell2 Is Nothing Then
Exit Sub
'do nothing
Else
DestCell.Value = FromCell.Value
DestCell2.Value = FromCell2.Value
End If

The Range "FromCell" is a merged cell in my sheet and even though i
delete everything in it the macro still goes forward with the "else"
part. How can this be?

"Nothing" in vba sense means that the cell is clear?

/Kasper
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,420
Default Problems with If "range" is nothing then

How about testing the value of the range variable rather than the variable
object?

--
__________________________________
HTH

Bob

"Kasper" wrote in message
...
This is the part of the macro and it doesn't work the way I intended
it to do.

If FromCell Is Nothing _
Or FromCell2 Is Nothing Then
Exit Sub
'do nothing
Else
DestCell.Value = FromCell.Value
DestCell2.Value = FromCell2.Value
End If

The Range "FromCell" is a merged cell in my sheet and even though i
delete everything in it the macro still goes forward with the "else"
part. How can this be?

"Nothing" in vba sense means that the cell is clear?

/Kasper



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Problems with If "range" is nothing then

The is Nothing does not seem to work try this instead

Sub Button1_Click()
Dim FromCell As Range, FromCell2 As Range, DestCell As Range, DestCell2
As Range
Set FromCell = Range("A1")
Set FromCell2 = Range("B1")
Set DestCell = Range("D1")
Set DestCell2 = Range("E1")

If FromCell = "" _
Or FromCell2 = "" Then
Exit Sub
'do nothing
Else
DestCell.Value = FromCell.Value
DestCell2.Value = FromCell2.Value
End If
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Problems with If "range" is nothing then

On 26 Feb., 12:13, "Bob Phillips" wrote:
How about testing the value of the range variable rather than the variable
object?

--
__________________________________
HTH

Bob

"Kasper" wrote in message

...



This is the part of the macro and it doesn't work the way I intended
it to do.


If FromCell Is Nothing _
* * * *Or FromCell2 Is Nothing Then
* * * *Exit Sub
* * * * * *'do nothing
* * * *Else
* * * * * *DestCell.Value = FromCell.Value
* * * * * *DestCell2.Value = FromCell2.Value
* * * *End If


The Range "FromCell" is a merged cell in my sheet and even though i
delete everything in it the macro still goes forward with the "else"
part. How can this be?


"Nothing" in vba sense means that the cell is clear?


/Kasper- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -


I'm not quite sure what you mean... That i should test on the given
cell e.g.("E9") instead?
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Problems with If "range" is nothing then

Check your earlier thread.

Kasper wrote:

This is the part of the macro and it doesn't work the way I intended
it to do.

If FromCell Is Nothing _
Or FromCell2 Is Nothing Then
Exit Sub
'do nothing
Else
DestCell.Value = FromCell.Value
DestCell2.Value = FromCell2.Value
End If

The Range "FromCell" is a merged cell in my sheet and even though i
delete everything in it the macro still goes forward with the "else"
part. How can this be?

"Nothing" in vba sense means that the cell is clear?

/Kasper


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,420
Default Problems with If "range" is nothing then

Either that or the value of the object

If FromCell.Value = "" Or FromCell2.value = "" Then


--
__________________________________
HTH

Bob

"Kasper" wrote in message
...
On 26 Feb., 12:13, "Bob Phillips" wrote:
How about testing the value of the range variable rather than the variable
object?

--
__________________________________
HTH

Bob

"Kasper" wrote in message

...



This is the part of the macro and it doesn't work the way I intended
it to do.


If FromCell Is Nothing _
Or FromCell2 Is Nothing Then
Exit Sub
'do nothing
Else
DestCell.Value = FromCell.Value
DestCell2.Value = FromCell2.Value
End If


The Range "FromCell" is a merged cell in my sheet and even though i
delete everything in it the macro still goes forward with the "else"
part. How can this be?


"Nothing" in vba sense means that the cell is clear?


/Kasper- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -


I'm not quite sure what you mean... That i should test on the given
cell e.g.("E9") instead?


  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 48
Default Problems with If "range" is nothing then

Thanks to all for your answers. They all work:-)

Have a good day.

/Kasper
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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
Array as a "named range" - formula ok in cells, but error as "named range" tskogstrom Excel Discussion (Misc queries) 11 December 28th 06 04:44 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


All times are GMT +1. The time now is 10:58 AM.

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"