How To Populate Strings Conditionally?

xlmaniac

Well-known Member
Joined
Jul 2, 2009
Messages
531
Office Version
  1. 2010
Platform
  1. Windows
Dear All,
I would like to populate strings based on the SKU & Store combinations.
The count of strings will be equal to # SKUs(Unique Count) X # Stores.
The strings could go into thousands/lakhs of rows.
I have the following sample data set across A1:B5.
IN A Column I have 3 Unique Count of SKUs and in Column B I Have 4 unique count of stores.
I would like to populate the strings(in this case it will be 12) in Column C.
[TABLE="width: 243"]
<tbody>[TR]
[TD]SKU[/TD]
[TD]Store[/TD]
[TD]SKU-Store Strings[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[TD]a[/TD]
[TD]1a[/TD]
[/TR]
[TR]
[TD="align: right"]2[/TD]
[TD]b[/TD]
[TD]1b[/TD]
[/TR]
[TR]
[TD="align: right"]3[/TD]
[TD]c[/TD]
[TD]1c[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]d[/TD]
[TD]1d[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]2a[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]2b[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]2c[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]2d[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]3a[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]3b[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]3c[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD]3d


Could somebody help me out with the solution Pls?
Regards[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
How about
Code:
Sub xlmaniac()
   Dim Ary1 As Variant, Ary2 As Variant, Nary As Variant
   Dim r1 As Long, r2 As Long, nr As Long
   
   Ary1 = Range("A2", Range("A" & Rows.Count).End(xlUp)).Value2
   Ary2 = Range("B2", Range("B" & Rows.Count).End(xlUp)).Value2
   ReDim Nary(1 To UBound(Ary1) * UBound(Ary2), 1 To 1)
   For r1 = 1 To UBound(Ary1)
      For r2 = 1 To UBound(Ary2)
         nr = nr + 1
         Nary(nr, 1) = Ary1(r1, 1) & Ary2(r2, 1)
      Next r2
   Next r1
   Range("C2").Resize(nr).Value = Nary
End Sub
 
Upvote 0
How about
Code:
Sub xlmaniac()
   Dim Ary1 As Variant, Ary2 As Variant, Nary As Variant
   Dim r1 As Long, r2 As Long, nr As Long
   
   Ary1 = Range("A2", Range("A" & Rows.Count).End(xlUp)).Value2
   Ary2 = Range("B2", Range("B" & Rows.Count).End(xlUp)).Value2
   ReDim Nary(1 To UBound(Ary1) * UBound(Ary2), 1 To 1)
   For r1 = 1 To UBound(Ary1)
      For r2 = 1 To UBound(Ary2)
         nr = nr + 1
         Nary(nr, 1) = Ary1(r1, 1) & Ary2(r2, 1)
      Next r2
   Next r1
   Range("C2").Resize(nr).Value = Nary
End Sub

Simply mesmerizing solution!!
It is working like a magic!!
Thank you so much for your kind support.
Really appreciate your help!!:):)
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,025
Members
452,542
Latest member
Bricklin

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