Try this:
VB Code:
Private Sub SplitRows() Dim oRange As Range, lRow As Long, lCol As Long, oOut As Worksheet, lOut As Long Dim sValue As String, sName As String Set oRange = Application.ActiveSheet.UsedRange 'Get the range of used cells. Set oOut = Application.ActiveWorkbook.Worksheets.Add 'Create an output worksheet. For lRow = 1 To oRange.Rows.Count 'Loop through all rows. sName = oRange.Cells(lRow, 1).Value 'Get the name from column A. sName = Trim$(sName) 'Trim it. If Len(sName) <> 0 Then 'Check to see if there is an entry. For lCol = 2 To oRange.Columns.Count 'Loop through the remaining columns. sValue = oRange.Cells(lRow, lCol).Value 'Get the value from that cell. sValue = Trim$(sValue) 'Trim it. If Len(sValue) <> 0 Then 'See if there is a value there. lOut = lOut + 1 'Increment the output row counter. oOut.Cells(lOut, 1).Value = sName 'Write the name cell. oOut.Cells(lOut, 2).Value = sValue 'Write the value cell. End If Next lCol End If Next lRow Set oRange = Nothing 'Release objects. Set oOut = Nothing End Sub




Reply With Quote