Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm working on a macro where an Application.Inputbox is used to have the
user enter a numerical value. When this variable is declared as Double, everything works as expected. However, for the error-checking code for the InputBox, it appears I need to use Variant as the value of this variable (if the input is not entered properly) will not be a numerical value in all cases. Multiple tests with varused as Variant return an incorrect calculation. Now, my question is as follows: is there a way to enter varused as a Variant, but to convert it to a Double after I performed my error-check for the Application.InputBox? I've included what I believe is all applicable code, in the hopes it better illustrates my problem. Any insight into why declaring varused As Variant causes my code to malfunction would be an added bonues. ;-) Thanks in advance for any assistance. k -- Dim LoadPerString As Double varused = Application.InputBox("Enter the value.") -- I was looking into some code to protect the macro in case the user entered nothing & clicked OK or clicked Cancel when the InputBox appeared. The code I'd like to use is as follows. -- Dim varused As Variant If varused = False Then MsgBox "You clicked cancel." Sheets("MainPage").Activate Application.ScreenUpdating = True Exit Sub ElseIf varused = "" Then MsgBox "You didn't enter anything." Sheets("MainPage").Activate Application.ScreenUpdating = True Exit Sub Else MsgBox "You entered: " & varused End If -- I got this code from the following post to this group. http://groups.google.com/groups?hl=e...sftngp05#link7 The calculations I am performing (not surprisingly, they originated in this group too) are as follows. -- Dim hi As Long, lo As Long Dim XRates As Range, YRates As Range Dim CountCells As Long ' combining ranges for interpolate function Set XRates = Range(startxrange & ":" & endxrange) Set YRates = Range(startyrange & ":" & endyrange) CountCells = XRates.Cells.Count If CountCells < YRates.Count Then MsgBox "The ranges need to be the same size." & vbCrLf & "This program will self-destruct." Exit Sub End If For hi = 1 To CountCells If XRates(hi) < LoadPerString Then Exit For Next If hi CountCells Then DesignTime = YRates(CountCells) ' copying design time to MainPage Worksheets("MainPage").Range("C19").FormulaR1C1 = DesignTime Sheets("MainPage").Activate Application.ScreenUpdating = True Exit Sub End If If hi = 1 Then DesignTime = YRates(hi) ' copying design time to MainPage Worksheets("MainPage").Range("C19").FormulaR1C1 = DesignTime Sheets("MainPage").Activate Application.ScreenUpdating = True Exit Sub End If lo = hi - 1 DesignTime = YRates(lo) + (varused - XRates(lo)) / _ (XRates(hi) - XRates(lo)) * _ (YRates(hi) - YRates(lo)) ' copying design time to MainPage Worksheets("MainPage").Range("C19").FormulaR1C1 = DesignTime Sheets("MainPage").Activate Application.ScreenUpdating = True -- |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel 2002 and VB declaring number as double | Excel Discussion (Misc queries) | |||
How do I assign range to variant and use | Excel Discussion (Misc queries) | |||
Testing if Variant is Range or Double? | Excel Programming | |||
Variant to String | Excel Programming | |||
DLLs and VBA: Who free's a variant? | Excel Programming |