|
お返事が遅くなり、すみません。
最初にこのページを開いたとき、沢山の書き込みがあって
胸が熱くなりました。
UO3さん、Yukiさん、ありがとうございます。
色々と取り入れて動作確認いたしました。
Sub sample1()
Dim r As Range
Dim i As Long
Dim z As Long
Dim aryCvt1 As Variant
Dim aryCvt2 As Variant
Dim idx As Long
Dim x As Long
Dim y As Long
Dim j As Long
Dim k As Long
Dim aCode As String
Dim aName As String
Dim mf As String
Dim w() As Variant
With Sheets("Sheet1")
Range("C:C,DU:DV").Delete Shift:=xlToLeft
Rows("1:2").Delete Shift:=xlUp
aryCvt1 = Array(" ", "男", "女")
aryCvt2 = Array("", "m", "f")
For idx = LBound(aryCvt1) To UBound(aryCvt1)
Cells.Replace What:=aryCvt1(idx), Replacement:=aryCvt2(idx), LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Next
With ActiveSheet.UsedRange
z = .Cells(.Cells.Count).Row
End With
For i = 3 To z Step 4
If r Is Nothing Then
Set r = Rows(i).Resize(2)
Else
Set r = Union(r, Rows(i).Resize(2))
End If
Next
End With
If Not r Is Nothing Then r.EntireRow.Delete
Rows("1:1").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("C1") = 0
Range("C1:DS1").DataSeries
With Sheets("Sheet1")
y = .Range("A" & .Rows.Count).End(xlUp).Row
x = .Cells(1, .Columns.Count).End(xlToLeft).Column
ReDim w(1 To .Rows.Count, 1 To 5)
For i = 2 To y Step 2
aCode = .Cells(i, "A").Value
aName = .Cells(i + 1, "A").Value
For z = i To i + 1
mf = .Cells(z, "B").Value
For j = 3 To x
k = k + 1
w(k, 1) = aCode
w(k, 2) = aName
w(k, 3) = mf
w(k, 4) = .Cells(1, j).Value
w(k, 5) = .Cells(z, j).Value
Next
Next
Next
End With
With Sheets("Sheet2")
.Cells.ClearContents
.Range("A1").Resize(k, UBound(w, 2)).Value = w
.Select
End With
With Sheets("Sheet2")
Rows("1:1").Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1:E1").Value = Array("code", "cyomei", "sex", "age", "pop")
MsgBox "完了!"
End With
End Sub
|
|