+ Reply to Thread
Results 1 to 3 of 3

UserForm Initialization

  1. #1
    Patrick Simonds
    Guest

    UserForm Initialization

    Any ideas why the code below would not work. The referenced cell (1,13) will
    either be blank, show 00:30 or 01:00.

    These values were placed in the cell with the following code:

    Dim lngValue 'As Long
    If OptionButton1.Value Then lngValue = ""
    If OptionButton2.Value Then lngValue = TimeSerial(0, 30, 0)
    If OptionButton3.Value Then lngValue = TimeSerial(0, 60, 0)
    rng(1, 13).Value = lngValue



    Private Sub UserForm_Initialize()

    Dim rng

    Set rng = Cells(ActiveCell.Row, 1)

    With ActiveCell.Offset(1, 13)
    If .Value = "" Then
    OptionButton1.Value = True
    ElseIf .Value = TimeSerial(0, 30, 0) Then
    OptionButton2.Value = True
    ElseIf .Value = TimeSerial(0, 60, 0) Then
    OptionButton3.Value = True
    End If
    End With

    End Sub



  2. #2
    Tom Ogilvy
    Guest

    Re: UserForm Initialization

    TimeSerial returns a double. Since your variable name is LngValue, I
    expect it is dimmed as Long and is the source of your problem (it returns
    zero for either TimeSerial value).

    --
    Regards,
    Tom Ogilvy


    "Patrick Simonds" <ordnance1@comcast.net> wrote in message
    news:%23Lg01g1$EHA.2196@TK2MSFTNGP14.phx.gbl...
    > Any ideas why the code below would not work. The referenced cell (1,13)

    will
    > either be blank, show 00:30 or 01:00.
    >
    > These values were placed in the cell with the following code:
    >
    > Dim lngValue 'As Long
    > If OptionButton1.Value Then lngValue = ""
    > If OptionButton2.Value Then lngValue = TimeSerial(0, 30, 0)
    > If OptionButton3.Value Then lngValue = TimeSerial(0, 60, 0)
    > rng(1, 13).Value = lngValue
    >
    >
    >
    > Private Sub UserForm_Initialize()
    >
    > Dim rng
    >
    > Set rng = Cells(ActiveCell.Row, 1)
    >
    > With ActiveCell.Offset(1, 13)
    > If .Value = "" Then
    > OptionButton1.Value = True
    > ElseIf .Value = TimeSerial(0, 30, 0) Then
    > OptionButton2.Value = True
    > ElseIf .Value = TimeSerial(0, 60, 0) Then
    > OptionButton3.Value = True
    > End If
    > End With
    >
    > End Sub
    >
    >




  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Quote Originally Posted by Patrick Simonds
    Any ideas why the code below would not work. The referenced cell (1,13) will
    either be blank, show 00:30 or 01:00.

    These values were placed in the cell with the following code:

    Dim lngValue 'As Long
    If OptionButton1.Value Then lngValue = ""
    If OptionButton2.Value Then lngValue = TimeSerial(0, 30, 0)
    If OptionButton3.Value Then lngValue = TimeSerial(0, 60, 0)
    rng(1, 13).Value = lngValue



    Private Sub UserForm_Initialize()

    Dim rng

    Set rng = Cells(ActiveCell.Row, 1)

    With ActiveCell.Offset(1, 13)
    If .Value = "" Then
    OptionButton1.Value = True
    ElseIf .Value = TimeSerial(0, 30, 0) Then
    OptionButton2.Value = True
    ElseIf .Value = TimeSerial(0, 60, 0) Then
    OptionButton3.Value = True
    End If
    End With

    End Sub

    Hello Patrick,

    All cells on the spreadsheet are of the variant data type. When testing a cell to check if it is empty, you must remember empty to variant means an empty string
    or "". If the cell has not held any data, the variant is unitialized and a NULL not EMPTY. Test for the Null condition along with the Empty and your problem should be solved.
    ________________________________________________________________

    Was:
    With ActiveCell.Offset(1, 13)
    If .Value = "" Then


    Change:
    With ActiveCell.Offset(1, 13)
    If IsNull(.Value) = True Or .Value = "" Then
    ________________________________________________________________

    Hope this helps,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1