write at exceltoexplore@gmail.com : Report Automation|Dashboard in Excel| Provide Excel consulting through macro (VBA) automation |Financial Modeling | Ethical Hacking

Tuesday, 21 June 2011

TRANSPOSE Column Value to Rows


suppose if you have multiple addresses in columns and you want to transpose it in rows then use below code


Try :
Sub test1()
Dim LR As Long, i As Long, j As Long, k As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
If Cells(1, 1).Value <> "" Then Cells(1, 1).EntireRow.Insert
Results = Array("Address :", "Area :", "Pin :", "Phone :")
Columns("A:A").Copy Destination:=ActiveSheet.Range("B1")
For p = 0 To UBound(Results, 1) Step 1
    Columns("B:B").Replace What:=Results(p), Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False
      Next
j = 1
k = 3
For i = 1 To LR
    With Range("B" & i)
        If .Value = "" Then
            j = j + 1
            k = 3
        Else
            k = k + 1
            Cells(j, k).Value = .Value
        End If
    End With
Next i
Columns("B").Delete
Cells(1, 3) = "Company Name"
Cells(1, 4) = "Address"
Cells(1, 5) = "Area"
Cells(1, 6) = "Pincode"
Cells(1, 7) = "Phone No"
Columns("A:G").AutoFit
End Sub


No comments:

Post a Comment