Assistance required to extend the existing code with slight change

bajrang2101

New Member
Joined
Dec 4, 2014
Messages
21
Dear All,

I have the following code which works for 2 columns(B & C) in my excel when Column A does not exist but I want it to work for the format defined as under:

Script #Step #Module
Script 1Step 1Comm
Step 2Comm
Step 3PD
Step 4PD
Step 5Comm
Step 6Broner
Step 7Broner
Step 8Broner
Script 2Step 1Finance
Step 2Finance
Step 3Finance
Step 4PD
Step 5Comm
Step 6Comm
Step 7
Step 8Comm
Step 9Comm
Step 10PD

<colgroup><col width="148" span="3" style="width:111pt"> </colgroup><tbody>
</tbody>

On running the macro it should give me the following desired results:

Script #Step #Module
Script 1Step 1
Step 2
Comm
Step 3
Step 4
PD
Step 5Comm
Step 6
Step 7
Broner
Script 2Step 1
Step 2
Step 3
Finance
Step 4PD
Step 5
Step 6
Comm
Step 7
Step 8
Step 9
Comm
Step 10PD

<colgroup><col><col><col></colgroup><tbody>
</tbody>

Code:
Sub alternative()
Dim lr As Long, c(), a, i As Long, k As Long, x, y
 
lr = Range("A" & Rows.Count).End(xlUp).Row
ReDim c(1 To lr, 1 To 2)
x = Application.WorksheetFunction.Match("Module", Range("A1:B1"), 0)
y = IIf(x = 1, 2, 1)
With Range("A1").Resize(lr, 2)
    a = .Value
    c(1, x) = a(1, x): c(1, y) = a(1, y): k = 1
    For i = 2 To lr
        If a(i, x) <> a(i - 1, x) Then
            k = k + 1
            c(k, x) = a(i, x)
            c(k, y) = a(i, y)
        Else
            c(k, y) = c(k, y) & vbLf & a(i, y)
        End If
    Next i
    .ClearContents
    .Resize(k, 2) = c
End With
'
End Sub


Please help me.

Many Thanks,
Bajrang
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
does this do what you want

Code:
Sub REORG()
With Range("D2:D" & Range("C" & Rows.Count).End(xlUp).Row)
    .Formula = "=IF(A2="""",IF(C2<>"""",IF(C2<>C1,TRUE,""#N/A""),""#N/A""),TRUE)"
    .Value = .Value
    .SpecialCells(xlCellTypeConstants, xlErrors).Offset(, -1).ClearContents
    .ClearContents
End With
End Sub
 
Upvote 0
One more query on this. Can this be tweaked to give me a range, as in Steps having same modules is displayed in a condensed form?

For Example:

Script #Step #Module
Script 1Step 1 - Step 6Comm-SD
Step 7 - Step 17FICO
Step 18
Step 19FICO

<colgroup><col width="148" span="3" style="width:111pt"> </colgroup><tbody>
</tbody>

This would greatly reduce the manual effort on the result obtained earlier.

Best Regards,
Bajrang
 
Upvote 0
Theoretically could be. But I do not understand how does the table on the left translates into the right table?



Excel 2013
ABCDEFG
1Script #Step #ModuleScript #Step #Module
2Script 1Step 1CommScript 1Step 1 - Step 6Comm-SD
3Step 2CommStep 7 - Step 17FICO
4Step 3PDStep 18
5Step 4PDStep 19FICO
6Step 5Comm
7Step 6Broner
8Step 7Broner
9Step 8Broner
10Script 2Step 1Finance
11Step 2Finance
12Step 3Finance
13Step 4PD
14Step 5Comm
15Step 6Comm
16Step 7
17Step 8Comm
18Step 9Comm
19Step 10PD
Sheet8
 
Upvote 0
I think there is a confusion because the example I pasted is just for illustration and is not the result of the actual query.

Please refer the below table for clear understanding.

Original DataResult obatained by current queryDesired Result (if Feasible)
Script #Step #ModuleScript #Step #ModuleScript #Step #Module
Script 1SIT3_107.002_DV03_1Comm-SDScript 1SIT3_107.002_DV03_1Comm-SDScript 1SIT3_107.002_DV03_1 - SIT3_107.002_DV03_7Comm-SD
SIT3_107.002_DV03_2Comm-SDSIT3_107.002_DV03_2 SIT3_107.002_DV03_8 - SIT3_107.002_DV03_19FICO
SIT3_107.002_DV03_3Comm-SDSIT3_107.002_DV03_3 SIT3_107.002_DV03_20 - SIT3_107.002_DV03_21Comm-SD
SIT3_107.002_DV03_4Comm-SDSIT3_107.002_DV03_4 SIT3_107.002_DV03_22FICO
SIT3_107.002_DV03_5Comm-SDSIT3_107.002_DV03_5 SIT3_107.002_DV03_23
SIT3_107.002_DV03_6Comm-SDSIT3_107.002_DV03_6 SIT3_107.002_DV03_24FICO
SIT3_107.002_DV03_7Comm-SDSIT3_107.002_DV03_7
SIT3_107.002_DV03_8FICOSIT3_107.002_DV03_8FICO
SIT3_107.002_DV03_9FICOSIT3_107.002_DV03_9
SIT3_107.002_DV03_10FICOSIT3_107.002_DV03_10
SIT3_107.002_DV03_11FICOSIT3_107.002_DV03_11
SIT3_107.002_DV03_12FICOSIT3_107.002_DV03_12
SIT3_107.002_DV03_13FICOSIT3_107.002_DV03_13
SIT3_107.002_DV03_14FICOSIT3_107.002_DV03_14
SIT3_107.002_DV03_15FICOSIT3_107.002_DV03_15
SIT3_107.002_DV03_16FICOSIT3_107.002_DV03_16
SIT3_107.002_DV03_17FICOSIT3_107.002_DV03_17
SIT3_107.002_DV03_18FICOSIT3_107.002_DV03_18
SIT3_107.002_DV03_19FICOSIT3_107.002_DV03_19
SIT3_107.002_DV03_20Comm-SDSIT3_107.002_DV03_20Comm-SD
SIT3_107.002_DV03_21Comm-SDSIT3_107.002_DV03_21
SIT3_107.002_DV03_22FICOSIT3_107.002_DV03_22FICO
SIT3_107.002_DV03_23SIT3_107.002_DV03_23
SIT3_107.002_DV03_24FICOSIT3_107.002_DV03_24FICO

<colgroup><col width="148" span="9" style="width:111pt"> </colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,217,350
Messages
6,136,055
Members
449,986
Latest member
Mark39841

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