Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Dennis
 
Posts: n/a
Default How to (re)set a range.value to pass -0- to a "double" variable

Using XL 2003

Sub PrintIf()
..........
Dim R As Range
Dim ThisPageTotal as Double
Set R = ActiveSheet.Cells(Rows.count, "P").End(xlUp)
ThisPageTotal = R.Value
If ThisPageTotal < 0 Then _
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
..........
End Sub

This above code works fine until it is used on a worksheet with no
dollar amount in the cell at ActiveSheet.Cells(Rows.count,
"P").End(xlUp)

When that happens, the code prints even though the cell may be empty.

OK R is a range.

When I "Watch" the Variables and there is a dollar value:

R may equal (i.e.) 411.27 (Range)
R.Value will equal 411.27 (Double)
ThisPageTotal = 411.27 (Double)

How does I set "R" to pass a -0- to R.Value AND to ThisPageTotal?

Set R.Value = 0 ?? or
Set R = Nothing ??

Dennis

  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

maybe...

Sub PrintIf()
..........
Dim R As Range
Dim ThisPageTotal as Double
Set R = ActiveSheet.Cells(Rows.count, "P").End(xlUp)
if isempty(R) then
msgbox "That cell is empty!
else
ThisPageTotal = R.Value
If ThisPageTotal < 0 Then _
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
..........
end if
end if
End Sub

If you have text in that cell, you may want to use a check like:

if application.isnumber(r.value) = false then
msgbox "It's not a number!
else
.....

application.isnumber(r.value) tests differently than VBA's isnumber(r.value).


Dennis wrote:

Using XL 2003

Sub PrintIf()
..........
Dim R As Range
Dim ThisPageTotal as Double
Set R = ActiveSheet.Cells(Rows.count, "P").End(xlUp)
ThisPageTotal = R.Value
If ThisPageTotal < 0 Then _
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
..........
End Sub

This above code works fine until it is used on a worksheet with no
dollar amount in the cell at ActiveSheet.Cells(Rows.count,
"P").End(xlUp)

When that happens, the code prints even though the cell may be empty.

OK R is a range.

When I "Watch" the Variables and there is a dollar value:

R may equal (i.e.) 411.27 (Range)
R.Value will equal 411.27 (Double)
ThisPageTotal = 411.27 (Double)

How does I set "R" to pass a -0- to R.Value AND to ThisPageTotal?

Set R.Value = 0 ?? or
Set R = Nothing ??

Dennis


--

Dave Peterson
  #3   Report Post  
Dennis
 
Posts: n/a
Default

Thanks Dave!

"Dave Peterson" wrote:

maybe...

Sub PrintIf()
..........
Dim R As Range
Dim ThisPageTotal as Double
Set R = ActiveSheet.Cells(Rows.count, "P").End(xlUp)
if isempty(R) then
msgbox "That cell is empty!
else
ThisPageTotal = R.Value
If ThisPageTotal < 0 Then _
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
..........
end if
end if
End Sub

If you have text in that cell, you may want to use a check like:

if application.isnumber(r.value) = false then
msgbox "It's not a number!
else
.....

application.isnumber(r.value) tests differently than VBA's isnumber(r.value).


Dennis wrote:

Using XL 2003

Sub PrintIf()
..........
Dim R As Range
Dim ThisPageTotal as Double
Set R = ActiveSheet.Cells(Rows.count, "P").End(xlUp)
ThisPageTotal = R.Value
If ThisPageTotal < 0 Then _
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
..........
End Sub

This above code works fine until it is used on a worksheet with no
dollar amount in the cell at ActiveSheet.Cells(Rows.count,
"P").End(xlUp)

When that happens, the code prints even though the cell may be empty.

OK R is a range.

When I "Watch" the Variables and there is a dollar value:

R may equal (i.e.) 411.27 (Range)
R.Value will equal 411.27 (Double)
ThisPageTotal = 411.27 (Double)

How does I set "R" to pass a -0- to R.Value AND to ThisPageTotal?

Set R.Value = 0 ?? or
Set R = Nothing ??

Dennis


--

Dave Peterson

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
Reset controls Slukes Excel Discussion (Misc queries) 0 March 30th 05 06:49 PM
How to reset Excel 2000 toolbars to "factory defaults"? [email protected] Excel Discussion (Misc queries) 3 March 28th 05 10:39 PM
How to pass values of a cell? Me Excel Discussion (Misc queries) 4 March 4th 05 05:35 PM
pass fail Tricia New Users to Excel 3 January 20th 05 03:45 PM
How to pass a workshhet name as a parameter into a subroutine ? yigalb Excel Discussion (Misc queries) 4 January 9th 05 10:28 AM


All times are GMT +1. The time now is 03:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"