VBA Code

vikas9385

Board Regular
Joined
Aug 29, 2009
Messages
96
I have following type of data:--

SAP CODENAMEH.Q01/01/201501/02/201501/03/201501/04/201501/05/201501/06/201501/07/201501/08/201501/09/201501/10/201501/11/201501/12/201501/13/201501/14/201501/15/201501/16/201501/17/201501/18/201501/19/201501/20/201501/21/201501/22/201501/23/201501/24/201501/25/201501/26/201501/27/201501/28/201501/29/201501/30/201501/31/2015
101AAbcL21S2CFA MEETINGS
102BDef111S211111S2
103Cabc111S211111S

<tbody>
</tbody>


but I need above data in following form:

SAP CODENAMEH.QDATEStatus
101AAbc01.01.2015L
102BDef01.01.20151
103Cabc01.01.20151
101AAbc01.02.20152
102BDef01.02.20151
103Cabc01.02.20151

<tbody>
</tbody>


Dates are in mm/dd/yyyy format


My reach:-

Code:
Sub Test()
    Dim ShNew As Worksheet
    Dim r, lr, lc As Long
    Dim c As Long
    Dim i As Long
    With ActiveSheet.Range("A1").CurrentRegion
        Set ShNew = Worksheets.Add
        i = 1
        .Rows(1).Resize(, 3).Copy ShNew.Range("A1")
        For c = 3 To .Columns.Count Step 1
            For r = 2 To .Rows.Count
                i = i + 1
                .Range("A" & r).Resize(, 3).Copy ShNew.Range("A" & i)
                .Cells(r, c).Resize(, 1).Copy ShNew.Range("D" & i)
            Next r
        Next c
    End With
    Sheets("Main").Select
     
    lr = WorksheetFunction.CountA(ActiveSheet.Range("a:a"))
    lc = WorksheetFunction.CountA(ActiveSheet.Range("1:1"))
    
    
    
    ShNew.Range("D1").Value = "Status"
    
    
    
    
    
End Sub

Please help
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi.

This should work. It is very similar to yours.
Code:
Sub Transpose()

    Dim iRow As Long, iCol As Long, outRow As Long
    Dim ws1 As Worksheet, ws2 As Worksheet
    Set ws1 = Worksheets("Sheet1")
    Set ws2 = Worksheets.Add
    
    outRow = 2
    ws2.Range("A1:E1") = Array("SAP CODE", "NAME", "H.Q", "DATE", "Status")
    
    For iCol = 4 To ws1.Range("A1").CurrentRegion.Columns.Count
        For iRow = 2 To ws1.Range("A1").CurrentRegion.Rows.Count
            If ws1.Cells(iRow, iCol) <> "" Then
                ws2.Cells(outRow, 1).Resize(, 3) = ws1.Cells(iRow, 1).Resize(, 3).Value
                ws2.Cells(outRow, 4) = ws1.Cells(1, iCol)
                ws2.Cells(outRow, 5) = ws1.Cells(iRow, iCol)
                outRow = outRow + 1
            End If
        Next iRow
    Next iCol
    
    ws2.Columns(4).NumberFormat = "MM/DD/YYYY"
    ws2.Columns("A:E").AutoFit
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,077
Members
449,094
Latest member
mystic19

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