+ Reply to Thread
Results 1 to 3 of 3

I would like to create a button on the worksheet to work a macro

  1. #1
    Steved
    Guest

    I would like to create a button on the worksheet to work a macro

    Hello from Steved

    Please how would I go about creating a button on the worksheet to work the
    below macro. Thankyou.

    Sub FindPart()
    Dim res As String, saddr As String
    Dim RgToSearch As Range, RgFound As Range
    Dim secondValue As String
    Set RgToSearch = ActiveSheet.Range("C:C")

    res = Application.InputBox("Type School Number ie 001,8.00", _
    "Find School", , , , , , 2)
    If res = "False" Then Exit Sub 'exit if Cancel is clicked
    res = Trim(UCase(res))
    If res = "" Then Exit Sub 'exit if no entry and OK is clicked
    If InStr(1, res, ",", vbTextCompare) = 0 Then
    MsgBox "Invalid entry"
    Exit Sub
    End If
    v = Split(res, ",")
    res = Trim(v(LBound(v)))
    secondValue = Trim(v(UBound(v)))
    Set RgFound = RgToSearch.Find(what:=res, _
    LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
    If RgFound Is Nothing Then
    MsgBox "School " & res & " not found."
    Exit Sub
    Else
    saddr = RgFound.Address
    Do
    If RgFound.Offset(0, 1).Text = secondValue Then
    Application.Goto Reference:= _
    RgFound.Offset(0, -1).Address(True, True, xlR1C1)
    Exit Do
    End If
    Set RgFound = RgToSearch.FindNext(RgFound)
    Loop While RgFound.Address <> saddr

    End If

  2. #2
    Tom Ogilvy
    Guest

    Re: I would like to create a button on the worksheet to work a macro

    Put the complete subroutine in a general module (Insert=>Module).

    go back to the worksheet and in Tools=>Customize, click the Forms toolbar on
    the first tab, or on the menu, right click and select Forms

    Click the button icon on the toolbar, then go to the sheet and click with
    the mouse, holding the button down, drag down and to the right to get the
    size of the button you want.

    You should then get the assign macro dialog, select your macro.

    or right click on the button and select assign macro, then select your
    macro.

    --
    Regards,
    Tom Ogilvy


    "Steved" <Steved@discussions.microsoft.com> wrote in message
    news:10C98D8F-7A6C-47AF-A50B-86DABC06EFC4@microsoft.com...
    > Hello from Steved
    >
    > Please how would I go about creating a button on the worksheet to work the
    > below macro. Thankyou.
    >
    > Sub FindPart()
    > Dim res As String, saddr As String
    > Dim RgToSearch As Range, RgFound As Range
    > Dim secondValue As String
    > Set RgToSearch = ActiveSheet.Range("C:C")
    >
    > res = Application.InputBox("Type School Number ie 001,8.00", _
    > "Find School", , , , , , 2)
    > If res = "False" Then Exit Sub 'exit if Cancel is clicked
    > res = Trim(UCase(res))
    > If res = "" Then Exit Sub 'exit if no entry and OK is clicked
    > If InStr(1, res, ",", vbTextCompare) = 0 Then
    > MsgBox "Invalid entry"
    > Exit Sub
    > End If
    > v = Split(res, ",")
    > res = Trim(v(LBound(v)))
    > secondValue = Trim(v(UBound(v)))
    > Set RgFound = RgToSearch.Find(what:=res, _
    > LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
    > If RgFound Is Nothing Then
    > MsgBox "School " & res & " not found."
    > Exit Sub
    > Else
    > saddr = RgFound.Address
    > Do
    > If RgFound.Offset(0, 1).Text = secondValue Then
    > Application.Goto Reference:= _
    > RgFound.Offset(0, -1).Address(True, True, xlR1C1)
    > Exit Do
    > End If
    > Set RgFound = RgToSearch.FindNext(RgFound)
    > Loop While RgFound.Address <> saddr
    >
    > End If




  3. #3
    Steved
    Guest

    Re: I would like to create a button on the worksheet to work a mac

    Thankyou.

    "Tom Ogilvy" wrote:

    > Put the complete subroutine in a general module (Insert=>Module).
    >
    > go back to the worksheet and in Tools=>Customize, click the Forms toolbar on
    > the first tab, or on the menu, right click and select Forms
    >
    > Click the button icon on the toolbar, then go to the sheet and click with
    > the mouse, holding the button down, drag down and to the right to get the
    > size of the button you want.
    >
    > You should then get the assign macro dialog, select your macro.
    >
    > or right click on the button and select assign macro, then select your
    > macro.
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Steved" <Steved@discussions.microsoft.com> wrote in message
    > news:10C98D8F-7A6C-47AF-A50B-86DABC06EFC4@microsoft.com...
    > > Hello from Steved
    > >
    > > Please how would I go about creating a button on the worksheet to work the
    > > below macro. Thankyou.
    > >
    > > Sub FindPart()
    > > Dim res As String, saddr As String
    > > Dim RgToSearch As Range, RgFound As Range
    > > Dim secondValue As String
    > > Set RgToSearch = ActiveSheet.Range("C:C")
    > >
    > > res = Application.InputBox("Type School Number ie 001,8.00", _
    > > "Find School", , , , , , 2)
    > > If res = "False" Then Exit Sub 'exit if Cancel is clicked
    > > res = Trim(UCase(res))
    > > If res = "" Then Exit Sub 'exit if no entry and OK is clicked
    > > If InStr(1, res, ",", vbTextCompare) = 0 Then
    > > MsgBox "Invalid entry"
    > > Exit Sub
    > > End If
    > > v = Split(res, ",")
    > > res = Trim(v(LBound(v)))
    > > secondValue = Trim(v(UBound(v)))
    > > Set RgFound = RgToSearch.Find(what:=res, _
    > > LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
    > > If RgFound Is Nothing Then
    > > MsgBox "School " & res & " not found."
    > > Exit Sub
    > > Else
    > > saddr = RgFound.Address
    > > Do
    > > If RgFound.Offset(0, 1).Text = secondValue Then
    > > Application.Goto Reference:= _
    > > RgFound.Offset(0, -1).Address(True, True, xlR1C1)
    > > Exit Do
    > > End If
    > > Set RgFound = RgToSearch.FindNext(RgFound)
    > > Loop While RgFound.Address <> saddr
    > >
    > > End If

    >
    >
    >


+ 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