Prompt User To Sort Data IF required

Mister H

Well-known Member
Joined
Mar 6, 2002
Messages
1,507
Hi All:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I am wondering if it is possible using VBA to ask a user if they would like to sort the data on a worksheet (titled Master) and if so allow them to select the sorting method?<o:p></o:p>
<o:p></o:p>
I have a macro I am using that compiles all the workbook in a folder. After the data i compiled I =would like to ask the user if they want to sort the data. If they choose yes then show them the column heading in Row 1 and allow them to select how they wish to sort their data. If they choose not to sort it then just exit the sub.<o:p></o:p>


Can someone tell me if this is possible :confused: and if so get me pointed in the right direction? I searched here and Google but have not yet come across an answer. :biggrin:

THANKS,
Mark
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi Mark.

Maybe like this

Code:
Sub sorttest()
If MsgBox("Do you want to sort", vbQuestion + vbYesNo) = vbNo Then Exit Sub
Application.Dialogs(xlDialogSort).Show
End Sub
 
Upvote 0
THANKS VoG :biggrin: YOUR EXPERTISE is always appreciated :biggrin:

Is there a way to get it to default to Header Row as opposed to No Header Row?

Other then that this is exactly what I was looking for. :beerchug:

Take Care,
Mark
 
Upvote 0
Hi VoG:

I came up with this but I am uncertain if there is any negative to using it as I do not unedrstand it :)

Code:
Application.Dialogs(xlDialogSort).Show arg1:=xlTopToBottom, arg8:=xlYes
Also, I put in Cells.Select so it selects all the data. It seemed to have a problem if there was a blank row in the data. I don't think there would be a blank row but Just In Case :biggrin:

Code:
Sub SortOption()
'Call up the Sort Option at the users discretion
Cells.Select
If MsgBox("Do you want to sort the data that has been compiled?", vbQuestion + vbYesNo) = vbNo Then Exit Sub
 
'No Column Headers
'Application.Dialogs(xlDialogSort).Show
 
'with Column Headers
Application.Dialogs(xlDialogSort).Show arg1:=xlTopToBottom, arg8:=xlYes 
 
End Sub

ALso just in case anyone reuires the same here is the code I am using that compiles all the data from the Excel files contained in the selected folder:

Code:
Sub Consolidate()
'Author:     Jerry Beaucaire'
'Date:       9/15/2009     (2007 compatible)  (updated 4/29/2011)
'Summary:    Merge files in a specific folder into one master sheet (stacked)
'            Moves imported files into another folder
Dim fName As String, fPath As String, fPathDone As String
Dim LR As Long, NR As Long
Dim wbData As Workbook, wsMaster As Worksheet
'Setup
    Application.ScreenUpdating = False  'speed up macro execution
    Application.EnableEvents = False    'turn off other macros for now
    Application.DisplayAlerts = False   'turn off system messages for now
 
    Set wsMaster = ThisWorkbook.Sheets("Master")    'sheet report is built into
With wsMaster
    If MsgBox("Clear the old data first?", vbYesNo) = vbYes Then
        .Cells.Clear
        NR = 1
    Else
        NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1    'appends data to existing data
    End If
'Path and filename (edit this section to suit)
    'fPath = "C:\2011\Files\"            'remember final \ in this string
    MsgBox "Please select a folder with files to consolidate"
    Do
        With Application.FileDialog(msoFileDialogFolderPicker)
            .AllowMultiSelect = False
            .Show
            If .SelectedItems.Count > 0 Then
                fPath = .SelectedItems(1) & "\"
                Exit Do
            Else
                If MsgBox("No folder chose, do you wish to abort?", _
                    vbYesNo) = vbYes Then Exit Sub
            End If
        End With
    Loop
 
 
 
    fPathDone = fPath & "Imported\"     'remember final \ in this string
    On Error Resume Next
        MkDir fPathDone                 'creates the completed folder if missing
    On Error GoTo 0
    fName = Dir(fPath & "*.xls*")        'listing of desired files, edit filter as desired
'Import a sheet from found files
    Do While Len(fName) > 0
        If fName <> ThisWorkbook.Name Then              'don't reopen this file accidentally
            Set wbData = Workbooks.Open(fPath & fName)  'Open file
        'This is the section to customize, replace with your own action code as needed
            LR = Range("A" & Rows.Count).End(xlUp).Row  'Find last row
            If NR = 1 Then                              'copy the data AND titles
                Range("A1:A" & LR).EntireRow.Copy .Range("A" & NR)
            Else                                        'copy the data only
                Range("A2:A" & LR).EntireRow.Copy .Range("A" & NR)
            End If
 
            wbData.Close False                                'close file
            NR = .Range("A" & .Rows.Count).End(xlUp).Row + 1  'Next row
            Name fPath & fName As fPathDone & fName           'move file to IMPORTED folder
            fName = Dir                                       'ready next filename
        End If
    Loop
End With
ErrorExit:    'Cleanup
    ActiveSheet.Columns.AutoFit
    Application.DisplayAlerts = True         'turn system alerts back on
    Application.EnableEvents = True          'turn other macros back on
    Application.ScreenUpdating = True        'refreshes the screen
End Sub

Have a GREAT day ALL,
Mark :biggrin:
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top