Amend values populating an array?

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
303
Office Version
  1. 365
Platform
  1. Windows
I have the following (courtesy of one of you kind people) that works perfectly
VBA Code:
Dim d As Object, r As Range, c, a, i As Long
    Set d = CreateObject("scripting.dictionary")
    For Each r In ws1.Range("B3", ws1.Cells(Rows.Count, "B").End(xlUp))
        For Each c In Split(r, ",")
            d(c) = 1
        Next c
    Next r

a = Application.Transpose(d.keys)

So this populates an array with values from column B. Perfect.

However, I now need to amend this code so that it picks up column B, adds " | " and then column I.

So currently it might be populating the array with "C1234" but after it would be "C1234 | Training" for example.

The values in column B + I are always consistent for the value in column B (so for each C1234 in column B, it would always be Training in column I, it would never be C1234 and HR).

Is the code above modifiable or am I better off amending the source data prior to populating the array?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You could use:

VBA Code:
Dim d As Object, r As Range, c, a, i As Long
    Set d = CreateObject("scripting.dictionary")
    For Each r In ws1.Range("B3", ws1.Cells(Rows.Count, "B").End(xlUp))
       dim suffix as string
       suffix = "|" & ws1.cells(r.row, "I").value
        For Each c In Split(r, ",")
            d(c & suffix) = 1
        Next c
    Next r

a = Application.Transpose(d.keys)
 
Upvote 0
Dim d As Object, r As Range, c, a, i As Long Set d = CreateObject("scripting.dictionary") For Each r In ws1.Range("B3", ws1.Cells(Rows.Count, "B").End(xlUp)) dim suffix as string suffix = "|" & ws1.cells(r.row, "I").value For Each c In Split(r, ",") d(c & suffix) = 1 Next c Next r a = Application.Transpose(d.keys)
Brilliant thank you, it works a treat.

I did have a stab at it myself but just ended up plagiarizing the first bit of code
VBA Code:
        Dim d2 As Object, r2 As Range, c2, a2, i2 As Long
    Set d2 = CreateObject("scripting.dictionary")
    For Each r2 In ws1.Range("I3", ws1.Cells(Rows.Count, "I").End(xlUp))
        For Each c2 In Split(r2, ",")
            d2(c2) = 1
        Next c2
    Next r2
    a2 = Application.Transpose(d2.keys)

 filename = a(i, 1) & " - " & a2(i, 1) & "_" & mth & "_" & yr & ".xlsx"

Yours is much neater - thanks again :)
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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