+ Reply to Thread
Results 1 to 3 of 3

If Question

  1. #1
    Greg B
    Guest

    If Question

    I am trying to make a macro where it is connected to a listbox. I have a
    problem of if a blank cell of the listbox is hit by accident it comes up
    with the debug error. I am trying to get around this by writing a "IF" code
    but am a little stuck.

    I have this at the moment

    ActiveSheet.Range("A1").Offset(ListBox1.ListIndex).Select
    If ActiveCell = "" Then
    MsgBox ("idiot")
    End If

    Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True

    How do I only get it to go to the hyperlink section of the code only if the
    cell it chooses has text in it to fire the
    Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
    part of the code

    Any help would be great

    Thanks
    GReg



  2. #2
    Dave Peterson
    Guest

    Re: If Question

    Maybe just checking for a hyperlink first...

    if selection.hyperlinks.count > 0 then
    selection.hyperlinks(1).follow ....etc
    else
    msgbox "no link"
    end if


    Greg B wrote:
    >
    > I am trying to make a macro where it is connected to a listbox. I have a
    > problem of if a blank cell of the listbox is hit by accident it comes up
    > with the debug error. I am trying to get around this by writing a "IF" code
    > but am a little stuck.
    >
    > I have this at the moment
    >
    > ActiveSheet.Range("A1").Offset(ListBox1.ListIndex).Select
    > If ActiveCell = "" Then
    > MsgBox ("idiot")
    > End If
    >
    > Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
    >
    > How do I only get it to go to the hyperlink section of the code only if the
    > cell it chooses has text in it to fire the
    > Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
    > part of the code
    >
    > Any help would be great
    >
    > Thanks
    > GReg


    --

    Dave Peterson

  3. #3
    Greg B
    Guest

    Re: If Question

    Thank you Dave

    Works Great
    Greg
    "Dave Peterson" <[email protected]> wrote in message
    news:[email protected]...
    > Maybe just checking for a hyperlink first...
    >
    > if selection.hyperlinks.count > 0 then
    > selection.hyperlinks(1).follow ....etc
    > else
    > msgbox "no link"
    > end if
    >
    >
    > Greg B wrote:
    >>
    >> I am trying to make a macro where it is connected to a listbox. I have a
    >> problem of if a blank cell of the listbox is hit by accident it comes up
    >> with the debug error. I am trying to get around this by writing a "IF"
    >> code
    >> but am a little stuck.
    >>
    >> I have this at the moment
    >>
    >> ActiveSheet.Range("A1").Offset(ListBox1.ListIndex).Select
    >> If ActiveCell = "" Then
    >> MsgBox ("idiot")
    >> End If
    >>
    >> Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
    >>
    >> How do I only get it to go to the hyperlink section of the code only if
    >> the
    >> cell it chooses has text in it to fire the
    >> Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
    >> part of the code
    >>
    >> Any help would be great
    >>
    >> Thanks
    >> GReg

    >
    > --
    >
    > Dave Peterson




+ 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