Excelで横に並んだデータを項目毎に縦に並び替えたかった。
一個ずつコピペするのはめんどくさいので、こんなとき大活躍するのがVBA!!
数十行かけば一瞬で並び替えてくれます♪
Sub step1() Dim c As Range Set c = Me.Range("B2") Do Until c.Offset(0, -1).Value = "" If c.Value = Empty Then c.Value = c.Offset(0, -1).Value End If Set c = c.Offset(1) Loop End Sub Sub step2() Dim c As Range Dim i As Integer Dim s As Worksheet Dim e As Range Set s = ThisWorkbook.Sheets.Add Set e = s.Range("A1") Set c = Me.Range("B2") Do Until c.Offset(0, -1).Value = "" i = 0 Do Until c.Offset(0, i).Value = Empty e.Offset(0, 0).Value = c.Offset(0, -1).Value e.Offset(0, 1).Value = c.Offset(0, i).Value Set e = e.Offset(1) i = i + 1 Loop Set c = c.Offset(1) Loop End Sub