VBA to Simplify the String Data

sur

Board Regular
Joined
Jul 4, 2011
Messages
176
Hello All,


I have a String data here,


i have Code 123, Start Date, End Eade (common), in Cities 1 2 3 4 5 6 (May Vary).


Code Start Date End Date HYD BNG CHN MUM
123 9/19/2018 9/19/2018 1 1 1 1
234 9/20/2018 9/19/2018 1 1 1
234 9/19/2018 9/19/2018 1 1
532 9/19/2018 9/19/2018 1 1 1




Required:


123 9/19/2018 9/19/2018 HYD
123 9/19/2018 9/19/2018 BNG
123 9/19/2018 9/19/2018 CHN
123 9/19/2018 9/19/2018 MUM
234 9/20/2018 9/19/2018 BNG
234 9/20/2018 9/19/2018 CHN
234 9/20/2018 9/19/2018 MUM
234 9/19/2018 9/19/2018 HYD
234 9/19/2018 9/19/2018 BNG
532 9/19/2018 9/19/2018 HYD
532 9/19/2018 9/19/2018 BNG
532 9/19/2018 9/19/2018 CHN


Thanks,
SUR
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
This will use a new sheet to store the formatted data.
Code:
Sub t()
Dim sh As Worksheet, ssh As Worksheet, c As Range, lc As Long, i As Long
Set ssh = ActiveSheet
Set sh = Sheets.Add(After:=Sheets(ThisWorkbook.Sheets.Count))
With ssh
    For Each c In .Range("A2", .Cells(Rows.Count, 1).End(xlUp))
        If c <> "" Then
            lc = .Cells(c.Row, Columns.Count).End(xlToLeft).Column
            For i = 4 To lc
                If .Cells(c.Row, i) <> "" Then
                    sh.Cells(Rows.Count, 1).End(xlUp)(2).Resize(, 3) = c.Resize(, 3).Value
                    sh.Cells(Rows.Count, 1).End(xlUp).Offset(, 3) = .Cells(1, i).Value
                End If
            Next
        End If
    Next
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,753
Members
449,094
Latest member
dsharae57

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