PDA

View Full Version : VBA scrip to sort data inside sheet



bulletbolt
11-29-2019, 02:50 PM
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

snb
11-30-2019, 10:05 AM
Your sample file doesn't contain any.

Bob Phillips
12-01-2019, 04:52 AM
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).

bulletbolt
12-01-2019, 12:54 PM
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

Bob Phillips
12-01-2019, 01:13 PM
I don't get it, you say you cannot run macros and then a function (which is still code).