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:
[TABLE="width: 444"]
<colgroup><col width="148" span="3" style="width:111pt"> </colgroup><tbody>[TR]
[TD="class: xl63, width: 148"]Script #[/TD]
[TD="class: xl63, width: 148"]Step #[/TD]
[TD="class: xl63, width: 148"]Module[/TD]
[/TR]
[TR]
[TD="class: xl63"]Script 1[/TD]
[TD="class: xl64, width: 148"]Step 1[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 2[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl63"]Step 3[/TD]
[TD="class: xl63"]PD[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl63"]Step 4[/TD]
[TD="class: xl63"]PD[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl63"]Step 5[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 6[/TD]
[TD="class: xl63"]Broner[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl63"]Step 7[/TD]
[TD="class: xl63"]Broner[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl63"]Step 8[/TD]
[TD="class: xl63"]Broner[/TD]
[/TR]
[TR]
[TD="class: xl63"]Script 2[/TD]
[TD="class: xl64, width: 148"]Step 1[/TD]
[TD="class: xl63"]Finance[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 2[/TD]
[TD="class: xl63"]Finance[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 3[/TD]
[TD="class: xl63"]Finance[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 4[/TD]
[TD="class: xl63"]PD[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 5[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 6[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 7[/TD]
[TD="class: xl63"] [/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 8[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 9[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 10[/TD]
[TD="class: xl63"]PD
[/TD]
[/TR]
</tbody>[/TABLE]
On running the macro it should give me the following desired results:
[TABLE="width: 258"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]Script #[/TD]
[TD]Step #[/TD]
[TD]Module[/TD]
[/TR]
[TR]
[TD]Script 1[/TD]
[TD]Step 1
Step 2[/TD]
[TD]Comm[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 3
Step 4[/TD]
[TD]PD[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 5[/TD]
[TD]Comm[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 6
Step 7[/TD]
[TD]Broner[/TD]
[/TR]
[TR]
[TD]Script 2[/TD]
[TD]Step 1
Step 2
Step 3[/TD]
[TD]Finance[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 4[/TD]
[TD]PD[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 5
Step 6[/TD]
[TD]Comm[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 7[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 8
Step 9[/TD]
[TD]Comm[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 10[/TD]
[TD]PD[/TD]
[/TR]
</tbody>[/TABLE]
Please help me.
Many Thanks,
Bajrang
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:
[TABLE="width: 444"]
<colgroup><col width="148" span="3" style="width:111pt"> </colgroup><tbody>[TR]
[TD="class: xl63, width: 148"]Script #[/TD]
[TD="class: xl63, width: 148"]Step #[/TD]
[TD="class: xl63, width: 148"]Module[/TD]
[/TR]
[TR]
[TD="class: xl63"]Script 1[/TD]
[TD="class: xl64, width: 148"]Step 1[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 2[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl63"]Step 3[/TD]
[TD="class: xl63"]PD[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl63"]Step 4[/TD]
[TD="class: xl63"]PD[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl63"]Step 5[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 6[/TD]
[TD="class: xl63"]Broner[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl63"]Step 7[/TD]
[TD="class: xl63"]Broner[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl63"]Step 8[/TD]
[TD="class: xl63"]Broner[/TD]
[/TR]
[TR]
[TD="class: xl63"]Script 2[/TD]
[TD="class: xl64, width: 148"]Step 1[/TD]
[TD="class: xl63"]Finance[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 2[/TD]
[TD="class: xl63"]Finance[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 3[/TD]
[TD="class: xl63"]Finance[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 4[/TD]
[TD="class: xl63"]PD[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 5[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 6[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 7[/TD]
[TD="class: xl63"] [/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 8[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 9[/TD]
[TD="class: xl63"]Comm[/TD]
[/TR]
[TR]
[TD="class: xl63"] [/TD]
[TD="class: xl64, width: 148"]Step 10[/TD]
[TD="class: xl63"]PD
[/TD]
[/TR]
</tbody>[/TABLE]
On running the macro it should give me the following desired results:
[TABLE="width: 258"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]Script #[/TD]
[TD]Step #[/TD]
[TD]Module[/TD]
[/TR]
[TR]
[TD]Script 1[/TD]
[TD]Step 1
Step 2[/TD]
[TD]Comm[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 3
Step 4[/TD]
[TD]PD[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 5[/TD]
[TD]Comm[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 6
Step 7[/TD]
[TD]Broner[/TD]
[/TR]
[TR]
[TD]Script 2[/TD]
[TD]Step 1
Step 2
Step 3[/TD]
[TD]Finance[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 4[/TD]
[TD]PD[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 5
Step 6[/TD]
[TD]Comm[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 7[/TD]
[TD] [/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 8
Step 9[/TD]
[TD]Comm[/TD]
[/TR]
[TR]
[TD] [/TD]
[TD]Step 10[/TD]
[TD]PD[/TD]
[/TR]
</tbody>[/TABLE]
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