Help me kill an IF statement with 122 sub-ifs !!!

spyrule

Board Regular
Joined
Aug 21, 2015
Messages
114
Hello,

So I've got an interesting problem, and I'm debating on the best way to kill this bird.

I've got an excel sheet that contains the following (only it continues for 122 columns wide, and 80,000+ rows....):


skudescriptionACURAINTEGRATSXYEARHONDACIVICACCORD....
abc12394-01 Acura Integra, 94-97 Honda Accord, 88-91 Honda Civic CRX, 92-95 Honda Civic, 96-00 Honda Civic 4-2-1 Ceramic "K Series Swap" HeaderACURAINTEGRA94-01HONDACIVICACCORD94-97

<tbody>
</tbody>


  • Each Brand "Group" has been grouped and given a named range. For example Column C:F has been called "ACURAList".
  • each named range starts with the brand name and ends with YEAR.
  • Each YEAR cell is populated with the FIRST INSTANCE of a year range that is found ONLY (vast majority of our products only contain 1 year range)


What I'm trying to do is process through each one of these row, and generate an output on another specific tab called "YMMList".

This list will contain only the following:
MAKEMODELSKU
ACURAINTEGRA97-01
HONDAACCORD94-97
HONDACIVIC

<tbody>
</tbody>


Does anybody have a good/sample macro that can walk through each row, column group, by column group and process the output as shown?


Any, and ALL help is appreciated.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I know I have way too many variables but it's the end of the day and this seems to work. You will need to fill in the Sheet name that contains these Groups.

Code:
Sub YMMList()

Dim lRow As Long        'For the initial sheet
Dim YMMlRow As Long     'For identifying the append row of the output sheet
Dim i As Long           'Iterator for Groups, Start at column 3 and iterate in +4 increments
Dim lCol As Long        'Number of columns on initial sheet, assumes multiples of 4
Dim mRow As Long        'Iteration of rows in each Group
 
lCol = Sheets("insert initial sheet name").Cells(2, Columns.Count).End(xlToLeft).Column

For i = 3 To lCol Step 4
    lRow = Sheets("insert initial sheet name").Cells(Rows.Count, i).End(xlUp).Row
    
        For mCol = 2 To lRow
            YMMlRow = Sheets("YMMList").Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
            
            Sheets("YMMList").Range(Cells(YMMlRow, 1).Address & ":" & Cells(YMMlRow, 2).Address).Value = _
            Sheets("insert initial sheet name").Range(Cells(mCol, i).Address & ":" & Cells(mCol, i + 1).Address).Value
            Sheets("YMMList").Range(Cells(YMMlRow, 3).Address).Value = Sheets("insert initial sheet name").Range(Cells(mCol, i + 3).Address).Value
            
        Next mCol
        
Next i

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,558
Messages
6,125,507
Members
449,236
Latest member
Afua

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