+ Reply to Thread
Results 1 to 3 of 3

Creating a macro and form control button

Hybrid View

kaye.roberts393 Creating a macro and form... 04-09-2013, 01:44 PM
AndyLitch Re: Creating a macro and form... 04-09-2013, 02:02 PM
kaye.roberts393 Re: Creating a macro and form... 04-09-2013, 02:13 PM
  1. #1
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Creating a macro and form control button

    Private Sub CommandButton1_Click()
        Me.Hide
        Range("A1:B7").Select
        ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A1:A7"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("B1:B7"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Sheet1").Sort
            .SetRange Range("A1:B7")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        UserForm1.Show
    End Sub
    Elegant Simplicity............. Not Always

  2. #2
    Registered User
    Join Date
    02-27-2013
    Location
    Rancho Cucamonga, California
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Creating a macro and form control button

    Quote Originally Posted by AndyLitch View Post
    Private Sub CommandButton1_Click()
        Me.Hide
        Range("A1:B7").Select
        ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A1:A7"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("B1:B7"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Sheet1").Sort
            .SetRange Range("A1:B7")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        UserForm1.Show
    End Sub

    Would this need to be referenced in a new sheet? Sorry, still getting the hang of excel

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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