VBA Solution: Concatenate Range, Move Subsequently Created Values Into Single Column

SteveOranjinSteve

Board Regular
Joined
Nov 18, 2019
Messages
78
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,

Hope you are well. I am having difficulty composing a formula for a problem I'm having, and I may have to work through this issue again. What I'd like to do, is to concatenate a range of cells, so that I can create unique values (for a SKU-Country Code Combination) and then put all of those values into a single column. Here is how the data is set up.

ABCDEFG
1134555AEAEAEaeBNBN
2232545EAAEEeaeBNBN
3124142AWAEeaZNZNBX
4124142AEAEaeBCCBBC

a couple of points to be aware of.

  1. The data has NO HEADERS
  2. Horizontally, there is no general rule as to how far out the data goes. Sometimes it goes out 2 columns, sometimes 250 or 300 lines.
  3. Without exception, the country codes are two letters in length.
  4. Sometimes the SKUs are set up as depicted, sometimes they have "dashes" in them as well. I'd err on the side of caution and allow for letters as well.

The data in its final form should look something like this. Please let me know if you have any other questions.


134555AE
134555BN
232545AE
232545EE
232545BN
The results can be on the same tab, or on a new tab. it does not matter.

 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
How about
Rich (BB code):
Sub SteveOranjin()
   Dim ary As Variant
   Dim r As Long, c As Long
   
   ary = Sheets("Sheet1").Range("A1").CurrentRegion.Value2
   With CreateObject("scripting.dictionary")
      .CompareMode = 1
      For r = 1 To UBound(ary)
         For c = 2 To UBound(ary, 2)
            If ary(r, c) = "" Then Exit For
            .Item(ary(r, 1) & UCase(ary(r, c))) = Empty
         Next c
      Next r
      Sheets("Sheet2").Range("A1").Resize(.Count).Value = Application.Transpose(.Keys)
   End With
End Sub
change sheet names to suit
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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