Loop column then concatenate column (Scripting Dictionary)

SamKhem

Board Regular
Joined
Mar 18, 2024
Messages
50
Office Version
  1. 2016
Platform
  1. Windows
Dear Senior members

I would like request you guide by if column C = USD then join column B with D and E with scripting dictionary as below.
Book1
ABCDEF
1AABBUSDDDEEFF
21122JPY334455
3AABBTHBDDEEFF
41122USD334455
5AABBJPYDDEEFF
61122THB334455
7AABBUSDDDEEFF
81122JPY334455
9AABBTHBDDEEFF
101122USD334455
11AABBJPYDDEEFF
121122THB334455
13AABBUSDDDEEFF
141122JPY334455
15AABBTHBDDEEFF
161122USD334455
17AABBJPYDDEEFF
Sheet1
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I don't see how B is being join together with D and E. Which column is the expected result?
 
Upvote 0
Try:
VBA Code:
Sub JoinBDE()
    Dim ws As Worksheet
    Dim a, b
    
    Set ws = ThisWorkbook.Worksheets("Sheet1") 'change as needed
    a = ws.Range("A1").CurrentRegion.Value
    
    ReDim b(1 To UBound(a, 1), 1 To 1)
    For i = 1 To UBound(a, 1)
        If a(i, 3) = "USD" Then b(i, 1) = a(i, 2) & a(i, 4) & a(i, 5)
    Next i
    
    ws.Range("G1").Resize(UBound(b, 1), 1).Value = b
End Sub
Book2
ABCDEFG
1AABBUSDDDEEFFBBDDEE
21122JPY334455
3AABBTHBDDEEFF
41122USD334455223344
5AABBJPYDDEEFF
61122THB334455
7AABBUSDDDEEFFBBDDEE
81122JPY334455
9AABBTHBDDEEFF
101122USD334455223344
11AABBJPYDDEEFF
121122THB334455
13AABBUSDDDEEFFBBDDEE
141122JPY334455
15AABBTHBDDEEFF
161122USD334455223344
17AABBJPYDDEEFF
Sheet1
 
Upvote 0
Solution
It possible to run with million rows ? could you add scripting dictionary for more quick run?
Try:
VBA Code:
Sub JoinBDE()
    Dim ws As Worksheet
    Dim a, b
   
    Set ws = ThisWorkbook.Worksheets("Sheet1") 'change as needed
    a = ws.Range("A1").CurrentRegion.Value
   
    ReDim b(1 To UBound(a, 1), 1 To 1)
    For i = 1 To UBound(a, 1)
        If a(i, 3) = "USD" Then b(i, 1) = a(i, 2) & a(i, 4) & a(i, 5)
    Next i
   
    ws.Range("G1").Resize(UBound(b, 1), 1).Value = b
End Sub
Book2
ABCDEFG
1AABBUSDDDEEFFBBDDEE
21122JPY334455
3AABBTHBDDEEFF
41122USD334455223344
5AABBJPYDDEEFF
61122THB334455
7AABBUSDDDEEFFBBDDEE
81122JPY334455
9AABBTHBDDEEFF
101122USD334455223344
11AABBJPYDDEEFF
121122THB334455
13AABBUSDDDEEFFBBDDEE
141122JPY334455
15AABBTHBDDEEFF
161122USD334455223344
17AABBJPYDDEEFF
Sheet1
 
Upvote 0
It possible to run with million rows ? could you add scripting dictionary for more quick run?
It's working with an array that limits the interaction with the Excel sheet so it should be quick. Adding a dictionary here is unnecessary and it's not going to speed it up.
 
Upvote 0
It's working with array with limited interaction with the Excel sheet. Adding dictionary here is unnecessary and it's going to speed it up.
Thank always assist with excel question. Have a nice weekend.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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