Option Explicit
Function 対象の上行下行の位置を取得する()
Dim MyRange As Range
Dim lRow1 As Long
Dim lCol1 As Long
Dim lRow2 As Long
Dim lCol2 As Long
'上行取得・列固定(P16に選択した値/C7:C1000は選択されるべきリスト範囲)
For Each MyRange In Range("C7:C1000")
If MyRange.Text = Range("P16").Text Then
lRow1 = MyRange.Row
lCol1 = 13
Exit For
End If
Next
'下行取得・列固定(S16に選択した値/C7:C1000は選択されるべきリスト範囲)
For Each MyRange In Range("C7:C1000")
If MyRange.Text = Range("S16").Text Then
lRow1 = MyRange.Row
lCol1 = 13
Exit For
End If
Next
'実行
Call 上下両端入替え処理(lRow1, lCol1, lRow2, lCol2)
End Function
Function セル選択範囲の上下を入れ替える()
Dim lRow1 As Long
Dim lCol1 As Long
Dim lRow2 As Long
Dim lCol2 As Long
lRow1 = Selection.Row
lCol1 = Selection.Column
lRow2 = lRow1 + Selection.Rows.Count - 1
lCol2 = lCol1 + Selection.Columns.Count - 1
Call 上下両端入替え処理(lRow1, lCol1, lRow2, lCol2)
End Function
'------------------------------
' Test_Sample_Miniature
'------------------------------
Function 上下両端入替え処理( _
ByVal mlRow1 As Long, _
ByVal mlCol1 As Long, _
ByVal mlRow2 As Long, _
ByVal mlCol2 As Long _
)
Dim blnFLG As Boolean
Dim MyObj As Range
Dim MyObjWork As Range
Dim MyArray() As Variant
Dim MyNFLArray() As Variant
Dim iX As Integer
Dim lRow As Integer
Dim lCol As Integer
上下両端入替え処理 = False
For Each MyObj In Range(Cells(mlRow1, mlCol1), Cells(mlRow1, mlCol2))
'
iX = 0
lCol = MyObj.Column
For Each MyObjWork In Range(Cells(mlRow1, lCol), Cells(mlRow2, lCol))
iX = iX + 1
ReDim Preserve MyArray(iX - 1)
ReDim Preserve MyNFLArray(iX - 1)
MyArray(iX - 1) = MyObjWork.Formula
MyNFLArray(iX - 1) = MyObjWork.NumberFormatLocal
Next
'
iX = 0
For Each MyObjWork In Range(Cells(mlRow1, lCol), Cells(mlRow2, lCol))
'
'両端のみ処理する。
If MyObjWork.Row = mlRow1 Or MyObjWork.Row = mlRow2 Then
'
blnFLG = True
'
If (Left(MyArray(UBound(MyArray) - iX), 1) = "=") Then
blnFLG = False
End If
If (Left(MyObjWork.Formula, 1) = "=") Then
blnFLG = False
End If
If blnFLG = True Then
MyObjWork.Formula = MyArray(UBound(MyArray) - iX)
MyObjWork.NumberFormatLocal = MyNFLArray(UBound(MyNFLArray) - iX)
End If
'
End If
iX = iX + 1
'
Next
'
Next
上下両端入替え処理 = True
Exit Function
'**
Err_処理:
MsgBox "Error " & " ( " & Err.Number & " " & Err.Description & " )"
'**
End Function
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。