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:
<colgroup><col width="148" span="3" style="width:111pt"> </colgroup><tbody>
</tbody>
On running the macro it should give me the following desired results:
<colgroup><col><col><col></colgroup><tbody>
</tbody>
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:
Script # | Step # | Module |
Script 1 | Step 1 | Comm |
Step 2 | Comm | |
Step 3 | PD | |
Step 4 | PD | |
Step 5 | Comm | |
Step 6 | Broner | |
Step 7 | Broner | |
Step 8 | Broner | |
Script 2 | Step 1 | Finance |
Step 2 | Finance | |
Step 3 | Finance | |
Step 4 | PD | |
Step 5 | Comm | |
Step 6 | Comm | |
Step 7 | ||
Step 8 | Comm | |
Step 9 | Comm | |
Step 10 | PD |
<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 1 | Step 1 Step 2 | Comm |
Step 3 Step 4 | PD | |
Step 5 | Comm | |
Step 6 Step 7 | Broner | |
Script 2 | Step 1 Step 2 Step 3 | Finance |
Step 4 | PD | |
Step 5 Step 6 | Comm | |
Step 7 | ||
Step 8 Step 9 | Comm | |
Step 10 | PD |
<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