![]() |
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 |
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 |
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 |
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? |
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 |
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? |
Problems with If "range" is nothing then
Thanks to all for your answers. They all work:-)
Have a good day. /Kasper |
All times are GMT +1. The time now is 06:50 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com