|
▼ごん さん:
とりあえず「次善の策」としての「配列方式」です。
列は連続でも飛び飛びでもOKです。
また、2行目は見ていませんので仮にタイトル行でなくてもOKです。
Sub SampleV()
'配列方式
Dim myA As Range
Dim lCell As Range
Dim z As Long
Dim i As Long
Dim j As Long
Dim k As Long
Dim v As Variant
Dim w() As Variant
Dim vCols As Variant
Dim allB As Boolean
With ActiveSheet.UsedRange
Set lCell = .Cells(.Cells.Count)
End With
vCols = getCols(lCell.Column)
v = Range("A3", lCell).Value
ReDim w(1 To UBound(v, 1), 1 To UBound(v, 2))
For i = 1 To UBound(v, 1)
allB = True
For j = 1 To UBound(vCols)
If (Len(v(i, vCols(j)))) > 0 Then
allB = False
Exit For
End If
Next
If Not allB Then
k = k + 1
For j = 1 To UBound(w, 2)
w(k, j) = v(i, j)
Next
End If
Next
Range("A3").Resize(UBound(w, 1), UBound(w, 2)).Value = w
MsgBox "処理が完了しました"
End Sub
Private Function getCols(mCols As Long) As Variant
Dim a As Range, b As Range
Dim k As Long
Dim v() As Variant
ReDim v(1 To mCols)
For Each a In Selection.Areas
For Each b In a.Rows(1).Cells
k = k + 1
v(k) = b.Column
Next
Next
ReDim Preserve v(1 To k)
getCols = v
End Function
|
|