Consulting

Results 1 to 5 of 5

Thread: VBA scrip to sort data inside sheet

  1. #1

    VBA scrip to sort data inside sheet

    Hello all,

    I have a software that runs vba script which creates Excel file with certain data.

    I wish this data to be sorted based on two variables. It is way beyond my skills of sorting data before it's being dumped into the sheet, so I am trying to find an easier way.

    This script does use Excel template file for certain formatting. Within this file I have set up sort rules but once file is finnished sort is not applied. I can reopen the file, right mouse click->custom sort and the rules are there, as long as I press OK it sorts the data.

    Now the question is, is there a code which would replicate earlier described action?

    Thanks in advance

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Your sample file doesn't contain any.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Why not just dump it onto the sheet and use Excel's built-in sort (the macro recorder will give the gist of the code).
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    Sorry, failed to attach code, please find it below.

    xld - I cannot run macros because software will not recognize any other file extension, it must be excel template (tried save macros in excel template and it was not recognized). I cannot change this setting.

    Function GetPartListElement ( cmp, nr, cmpcnt, devnames )
        Dim le
        
        Set le = New CPartListElement
        With le
            .nr            = nr
            .count        = cmpcnt
            .name        = cmp.article
            If cmp.descl <> "" Then
                .desc    = GetTranslatedText( cmp.descl, SrcLanguage )        ' [11rk] Description by ComponentAttribute (projectlanguage)
            Else
                .desc    = GetTranslatedText( cmp.desc, SrcLanguage )        ' [11rk] Description by ComponentData
            End If
            .supp        = GetTranslatedText( cmp.supp, SrcLanguage )        ' [11rk]
            .price        = cmp.GetAttributeValue("Techdat3")
            .devices    = devnames
        End With
        Set le.cmp        = cmp
        Set le.devlst    = cmp.Devices
        If ADDED_COLUMN <> "" Then
            If cmp.id < 0 Then                            ' [15S]>
                le.addedinfo = cmp.GetAttributeValueAddedColumn( ADDED_COLUMN, cmp.name_ ) ' AdditionalPart not in project
            Else 
                le.addedinfo = cmp.GetAttributeValue( ADDED_COLUMN )
            End If                                    ' <[15S]
        End If
    
        Set GetPartListElement = le
    
    End Function

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I don't get it, you say you cannot run macros and then a function (which is still code).
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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