How can I generate a list of codes in Excel based on criteria?

bluesquared

New Member
Joined
Feb 24, 2020
Messages
2
Office Version
  1. 2010
Platform
  1. Windows

I'm trying to make a list of codes based on a format of 001 A 001. They should be 001 to 062, A to E, 001 to 012. I need all combinations, so they would be:


001 A 001
001 A 002 to
001 A 012, then up to 001 E 012

Then 001 B 001 to 012, and so on until 001 E 001 to 012
Then 002, A to E, 001 to 012

That's 3,720 combinations. I've tried making lookups to make a count within each of the three columns and generating +1 on the row above, I've tried IF statements to try and work it out, but I'm getting nowhere.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi there welcome to the forum. This piece of code will generate all your combinations in column A, starting at A1:
VBA Code:
Option Explicit

Sub CodeList()
    Dim Middle(5) As String
    Dim MidCount As Integer
    Dim RowCount As Integer
    Dim LeftBit As Integer
    Dim RightBit As Integer
    Application.ScreenUpdating = False
    Middle(1) = " A "
    Middle(2) = " B "
    Middle(3) = " C "
    Middle(4) = " D "
    Middle(5) = " E "
    RowCount = 1
    For LeftBit = 1 To 62
        For MidCount = 1 To 5
            For RightBit = 1 To 12
                Cells(RowCount, 1).Value = Format(LeftBit, "000") + Middle(MidCount) + Format(RightBit, "000")
                RowCount = RowCount + 1
            Next RightBit
        Next MidCount
    Next LeftBit
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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