<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic convert VBA logic to Qlik Sense in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/convert-VBA-logic-to-Qlik-Sense/m-p/2546539#M109945</link>
    <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;I need help converting this VBA code into Qlik Sense.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="language-vba"&gt;Sub FusionParReferenceEtDonneesUniques()
Dim wsSrc As Worksheet, wsDest As Worksheet
Dim dict As Object, lignesASupprimer As Collection
Dim refKey As Variant, i As Long
Dim codeFull As String, codeNum As String

Set wssrc=ThisWorkbook.Sheets("NOTILUS_MISS")
Set wsDest = ThisWorkbook.Sheets("Sheet1")
Set dict = CreateObject("Scripting.Dictionary")
Set lignesASupprimer = New Collection

Dim lastRowDest As Long: lastRowDest = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Row

For i = 2 To lastRowDest
If UCase(Trim(wsDest.Cells(i, "A").Value)) = "MISSION/COMPTABILISATION/PAIEMENT" Then
codeFull = wsDest.Cells(i, "J").Value
codeNum = ExtractNumber(codeFull)
If codeNum &amp;lt;&amp;gt; "" Then
If Not dict.Exists(codeNum) Then
Set dict(codeNum) = CreateObject("Scripting.Dictionary")
dict(codeNum)("Row") = i
dict(codeNum)("MontantTotal") = ToDouble(wsDest.Cells(i, "M"))
Else
dict(codeNum)("MontantTotal") = dict(codeNum)("MontantTotal") + ToDouble(wsDest.Cells(i, "M"))
lignesASupprimer.Add i
End If
End If
End If
Next i

For Each refKey In dict.Keys
Dim rowCible As Long: rowCible = dict(refKey)("Row")
wsDest.Cells(rowCible, "I").Value = wsDest.Cells(rowCible, "K").Value
wsDest.Cells(rowCible, "M").Value = dict(refKey)("MontantTotal")
Next refKey

For i = lignesASupprimer.Count To 1 Step -1
wsDest.Rows(lignesASupprimer(i)).Delete
Next i
End Sub
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would like to reproduce this logic using &lt;CODE&gt;FirstValue()&lt;/CODE&gt;.&lt;/P&gt;
&lt;P&gt;So far, I have created three tables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="language-sql"&gt;NoConcatenate
WS_Mission:
LOAD
    *,
    KeepChar([codeFull], '0123456789') AS codeNum,
    [Montant] AS MontantNum
RESIDENT WS_Final
WHERE NOT (
    Upper([Rub]) = 'MISSION/COMPTABILISATION/PAIEMENT'
    AND Len([codeFull]) &amp;gt; 0
);

NoConcatenate
WS_Mission_1:
LOAD
    *,
    KeepChar([codeFull], '0123456789') AS codeNum,
    [Montant] AS MontantNum
RESIDENT WS_Final
WHERE Upper([Rub]) = 'MISSION/COMPTABILISATION/PAIEMENT'
  AND Len([codeFull]) &amp;gt; 0;

NoConcatenate
Mission_Agreg:
LOAD
    codeNum,
    Sum(MontantNum) AS MontantTotal
RESIDENT WS_Mission_1
GROUP BY codeNum;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;At this point, I’m not sure how to:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P&gt;remove duplicates (keeping one row per &lt;CODE&gt;codeNum&lt;/CODE&gt;)&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;apply &lt;CODE&gt;FirstValue()&lt;/CODE&gt; logic&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;and perform the correct joins to rebuild the final table&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Any guidance would be greatly appreciated.&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Thu, 09 Apr 2026 15:12:41 GMT</pubDate>
    <dc:creator>rbeb</dc:creator>
    <dc:date>2026-04-09T15:12:41Z</dc:date>
    <item>
      <title>convert VBA logic to Qlik Sense</title>
      <link>https://community.qlik.com/t5/App-Development/convert-VBA-logic-to-Qlik-Sense/m-p/2546539#M109945</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;I need help converting this VBA code into Qlik Sense.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="language-vba"&gt;Sub FusionParReferenceEtDonneesUniques()
Dim wsSrc As Worksheet, wsDest As Worksheet
Dim dict As Object, lignesASupprimer As Collection
Dim refKey As Variant, i As Long
Dim codeFull As String, codeNum As String

Set wssrc=ThisWorkbook.Sheets("NOTILUS_MISS")
Set wsDest = ThisWorkbook.Sheets("Sheet1")
Set dict = CreateObject("Scripting.Dictionary")
Set lignesASupprimer = New Collection

Dim lastRowDest As Long: lastRowDest = wsDest.Cells(wsDest.Rows.Count, "A").End(xlUp).Row

For i = 2 To lastRowDest
If UCase(Trim(wsDest.Cells(i, "A").Value)) = "MISSION/COMPTABILISATION/PAIEMENT" Then
codeFull = wsDest.Cells(i, "J").Value
codeNum = ExtractNumber(codeFull)
If codeNum &amp;lt;&amp;gt; "" Then
If Not dict.Exists(codeNum) Then
Set dict(codeNum) = CreateObject("Scripting.Dictionary")
dict(codeNum)("Row") = i
dict(codeNum)("MontantTotal") = ToDouble(wsDest.Cells(i, "M"))
Else
dict(codeNum)("MontantTotal") = dict(codeNum)("MontantTotal") + ToDouble(wsDest.Cells(i, "M"))
lignesASupprimer.Add i
End If
End If
End If
Next i

For Each refKey In dict.Keys
Dim rowCible As Long: rowCible = dict(refKey)("Row")
wsDest.Cells(rowCible, "I").Value = wsDest.Cells(rowCible, "K").Value
wsDest.Cells(rowCible, "M").Value = dict(refKey)("MontantTotal")
Next refKey

For i = lignesASupprimer.Count To 1 Step -1
wsDest.Rows(lignesASupprimer(i)).Delete
Next i
End Sub
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would like to reproduce this logic using &lt;CODE&gt;FirstValue()&lt;/CODE&gt;.&lt;/P&gt;
&lt;P&gt;So far, I have created three tables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="language-sql"&gt;NoConcatenate
WS_Mission:
LOAD
    *,
    KeepChar([codeFull], '0123456789') AS codeNum,
    [Montant] AS MontantNum
RESIDENT WS_Final
WHERE NOT (
    Upper([Rub]) = 'MISSION/COMPTABILISATION/PAIEMENT'
    AND Len([codeFull]) &amp;gt; 0
);

NoConcatenate
WS_Mission_1:
LOAD
    *,
    KeepChar([codeFull], '0123456789') AS codeNum,
    [Montant] AS MontantNum
RESIDENT WS_Final
WHERE Upper([Rub]) = 'MISSION/COMPTABILISATION/PAIEMENT'
  AND Len([codeFull]) &amp;gt; 0;

NoConcatenate
Mission_Agreg:
LOAD
    codeNum,
    Sum(MontantNum) AS MontantTotal
RESIDENT WS_Mission_1
GROUP BY codeNum;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;At this point, I’m not sure how to:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P&gt;remove duplicates (keeping one row per &lt;CODE&gt;codeNum&lt;/CODE&gt;)&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;apply &lt;CODE&gt;FirstValue()&lt;/CODE&gt; logic&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;and perform the correct joins to rebuild the final table&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Any guidance would be greatly appreciated.&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 09 Apr 2026 15:12:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/convert-VBA-logic-to-Qlik-Sense/m-p/2546539#M109945</guid>
      <dc:creator>rbeb</dc:creator>
      <dc:date>2026-04-09T15:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: convert VBA logic to Qlik Sense</title>
      <link>https://community.qlik.com/t5/App-Development/convert-VBA-logic-to-Qlik-Sense/m-p/2546542#M109946</link>
      <description>&lt;P&gt;Please try the attached code.&lt;/P&gt;&lt;P&gt;You'll need to update some paths within the code prior to running but I've included comments to assist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Key translation decisions explained&lt;/P&gt;&lt;P class=""&gt;&lt;STRONG&gt;Removing duplicates → GROUP BY + FirstValue()&lt;/STRONG&gt;&lt;/P&gt;&lt;P class=""&gt;Your VBA keeps the first row it encounters and deletes the rest. In Qlik that's&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;PRE&gt;&lt;SPAN&gt;FirstValue&lt;SPAN class=""&gt;(&lt;/SPAN&gt;ColK&lt;SPAN class=""&gt;)&lt;/SPAN&gt; &lt;SPAN class=""&gt;AS&lt;/SPAN&gt; ColK_First&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P class=""&gt;FirstValue() returns the value from whichever row was loaded first for that CodeNum group — same behavior as your dictionary storing only the initial row index.&lt;/P&gt;&lt;P class=""&gt;&lt;STRONG&gt;Summing MontantTotal → Sum(Montant)&lt;/STRONG&gt;&lt;/P&gt;&lt;P class=""&gt;The VBA accumulates dict(codeNum)("MontantTotal") += ... across duplicates. Sum(Montant) grouped by CodeNum is the direct equivalent.&lt;/P&gt;&lt;P class=""&gt;&lt;STRONG&gt;ColI ← ColK replacement&lt;/STRONG&gt;&lt;/P&gt;&lt;P class=""&gt;Your macro does wsDest.Cells(rowCible, "I").Value = wsDest.Cells(rowCible, "K").Value on the surviving row. In the script, ColI is simply aliased from ColK_First — no patch-after-the-fact needed.&lt;/P&gt;&lt;P class=""&gt;&lt;STRONG&gt;ExtractNumber() → PurgeChar()&lt;/STRONG&gt;&lt;/P&gt;&lt;P class=""&gt;Since I don't have the source of ExtractNumber, I used PurgeChar() to strip all non-digit characters. If your codes follow a more specific pattern (e.g. always 6 digits after a slash), replace with:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Mid&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;J&lt;SPAN class=""&gt;,&lt;/SPAN&gt; &lt;SPAN class=""&gt;Index&lt;/SPAN&gt;&lt;SPAN class=""&gt;(&lt;/SPAN&gt;J&lt;SPAN class=""&gt;,&lt;/SPAN&gt; &lt;SPAN class=""&gt;'/'&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt; &lt;SPAN class=""&gt;+&lt;/SPAN&gt; &lt;SPAN class=""&gt;1&lt;/SPAN&gt;&lt;SPAN class=""&gt;,&lt;/SPAN&gt; &lt;SPAN class=""&gt;6&lt;/SPAN&gt;&lt;SPAN class=""&gt;)&lt;/SPAN&gt; &lt;SPAN class=""&gt;AS&lt;/SPAN&gt; CodeNum&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;HR /&gt;&lt;P&gt;What you'll need to adjust&lt;/P&gt;&lt;DIV class=""&gt;Item What to change lib://YourDataConnection/... Your actual Qlik data connection name table is NOTILUS_MISS Confirm sheet name matches exactly PurgeChar(...) regex Match whatever ExtractNumber() actually does Column letters A/I/J/K/M If your load uses named fields, replace with actual field names&lt;/DIV&gt;</description>
      <pubDate>Thu, 09 Apr 2026 16:18:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/convert-VBA-logic-to-Qlik-Sense/m-p/2546542#M109946</guid>
      <dc:creator>WeLoveQlik</dc:creator>
      <dc:date>2026-04-09T16:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: convert VBA logic to Qlik Sense</title>
      <link>https://community.qlik.com/t5/App-Development/convert-VBA-logic-to-Qlik-Sense/m-p/2546596#M109950</link>
      <description>&lt;P&gt;hello&lt;/P&gt;
&lt;P&gt;ExtractNumber is a function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Function ExtractNumber(str As String) As String&lt;BR /&gt;Dim i As Long, result As String&lt;BR /&gt;result = ""&lt;BR /&gt;For i = 1 To Len(str)&lt;BR /&gt;If Mid(str, i, 1) Like "#" Then&lt;BR /&gt;result = result &amp;amp; Mid(str, i, 1)&lt;BR /&gt;End If&lt;BR /&gt;Next i&lt;BR /&gt;ExtractNumber = result&lt;BR /&gt;End Function&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2026 07:15:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/convert-VBA-logic-to-Qlik-Sense/m-p/2546596#M109950</guid>
      <dc:creator>rbeb</dc:creator>
      <dc:date>2026-04-10T07:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: convert VBA logic to Qlik Sense</title>
      <link>https://community.qlik.com/t5/App-Development/convert-VBA-logic-to-Qlik-Sense/m-p/2546633#M109957</link>
      <description>&lt;P&gt;Personally I would start with a different approach by loading the data from a resident table to ensure a defined sorting of the records to be able to apply interrecord-functions to number them in regard to the needed keys. And within this the n conditions are resolved in n flags. This may look like:&lt;/P&gt;&lt;P&gt;load *,&amp;nbsp;rowno() as RowNo where Flag;&lt;BR /&gt;load *, if(X = 'a' and Y = 'b', true(), false()) as Flag;&lt;BR /&gt;load&lt;BR /&gt;&amp;nbsp; &amp;nbsp;*,&lt;BR /&gt;&amp;nbsp; &amp;nbsp;recno() as RecNo,&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;if(MyKey = previous(MyKey), peek('Nr') + 1, 1) as Nr,&lt;BR /&gt;&amp;nbsp; &amp;nbsp;keepchar(Code, '0123456789') as X, purgechar(Code, '0123456789') as Y,&lt;BR /&gt;&amp;nbsp; &amp;nbsp;if(Field1 = 'x', 1, 0) as A,&amp;nbsp;if(Field2 = 'y', 1, 0) as B&lt;BR /&gt;resident PreLoad order by MyKey;&lt;/P&gt;&lt;P&gt;It's a simplified demo of the logic to show how to track the source + target records as well as the in between numbering of a key-field (it's also possible against n fields but often it's simpler to combine them in beforehand). Also n conditions could be included in one of n preceding load-layer to flag and/or filter the records which may also include in the end the Nr = 1.&lt;/P&gt;&lt;P&gt;Even expensive and complex matching and filtering logic are quickly developed - step by step expanding to the next part.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2026 13:07:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/convert-VBA-logic-to-Qlik-Sense/m-p/2546633#M109957</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2026-04-10T13:07:21Z</dc:date>
    </item>
  </channel>
</rss>

