bajrang2101
New Member
- Joined
- Dec 4, 2014
- Messages
- 21
Dear All,
I have the following code which is working fine when I am using the columns as under:
Module Step #
Comm Step 1
Comm Step 2
PD Step 3
Comm Step 4
Comm Step 5
Broner Step 6
Broner Step 7
Broner Step 8
Sub alternative()
Dim lr As Long, c(), a, i As Long, k As Long
lr = Range("A" & Rows.Count).End(xlUp).Row
ReDim c(1 To lr, 1 To 2)
With Range("A1").Resize(lr, 2)
a = .Value
c(1, 1) = a(1, 1): c(1, 2) = a(1, 2): k = 1
For i = 2 To lr
If a(i, 1) <> a(i - 1, 1) Then
k = k + 1
c(k, 1) = a(i, 1)
c(k, 2) = a(i, 2)
Else
c(k, 2) = c(k, 2) & vbLf & a(i, 2)
End If
Next i
.ClearContents
.Resize(k, 2) = c
End With
End Sub
But I want to use this code when the same columns are reversed as mentioned and it should give the same result as earlier.
Step # Module
Step 1 Comm
Step 2 Comm
Step 3 PD
Step 4 Comm
Step 5 Comm
Step 6 Broner
Step 7 Broner
Step 8 Broner
Can anybody please help me modify the following code to give the desired result?
Thanks in advance..!
Best Regards,
Bajrang
I have the following code which is working fine when I am using the columns as under:
Module Step #
Comm Step 1
Comm Step 2
PD Step 3
Comm Step 4
Comm Step 5
Broner Step 6
Broner Step 7
Broner Step 8
Sub alternative()
Dim lr As Long, c(), a, i As Long, k As Long
lr = Range("A" & Rows.Count).End(xlUp).Row
ReDim c(1 To lr, 1 To 2)
With Range("A1").Resize(lr, 2)
a = .Value
c(1, 1) = a(1, 1): c(1, 2) = a(1, 2): k = 1
For i = 2 To lr
If a(i, 1) <> a(i - 1, 1) Then
k = k + 1
c(k, 1) = a(i, 1)
c(k, 2) = a(i, 2)
Else
c(k, 2) = c(k, 2) & vbLf & a(i, 2)
End If
Next i
.ClearContents
.Resize(k, 2) = c
End With
End Sub
But I want to use this code when the same columns are reversed as mentioned and it should give the same result as earlier.
Step # Module
Step 1 Comm
Step 2 Comm
Step 3 PD
Step 4 Comm
Step 5 Comm
Step 6 Broner
Step 7 Broner
Step 8 Broner
Can anybody please help me modify the following code to give the desired result?
Thanks in advance..!
Best Regards,
Bajrang