これはおそらく、私が一日数回やっものです。したがって、私は簡単に共有できるカスタム関数を作成しました。あなたが改善のためのアイデアを持っているなら、私はそれらを聞いて喜んでいます。
この
が関数である:あなたがアクティブシートの行1の最初の値を取得したい場合は、このように
Public Function fnLngLocateValueCol(ByVal strTarget As String,
ByRef wksTarget As Worksheet, _
Optional lngRow As Long = 1, _
Optional lngMoreValuesFound As Long = 1, _
Optional blnLookForPart = False, _
Optional blnLookUpToBottom = True) As Long
Dim lngValuesFound As Long
Dim rngLocal As Range
Dim rngMyCell As Range
fnLngLocateValueCol = -999
lngValuesFound = lngMoreValuesFound
With wksTarget
Set rngLocal = .Range(.Cells(lngRow, 1), .Cells(lngRow, Columns.Count))
End With
For Each rngMyCell In rngLocal
If blnLookForPart Then
If strTarget = Left(rngMyCell, Len(strTarget)) Then
If lngValuesFound = 1 Then
fnLngLocateValueCol = rngMyCell.Column
If blnLookUpToBottom Then Exit Function
Else
Call Decrement(lngValuesFound)
End If
End If
Else
If strTarget = Trim(rngMyCell) Then
If lngValuesFound = 1 Then
fnLngLocateValueCol = rngMyCell.Column
If blnLookUpToBottom Then Exit Function
Else
Call Decrement(lngValuesFound)
End If
End If
End If
Next rngMyCell
End Function
、あなたは次のように呼び出す:
fnLngLocateValueCol("valueToSearchFor",ActiveSheet)
第二の値について、あなたは次のように呼び出す:
:あなたはこのように呼んで最後の値については
?fnLngLocateValueCol("valueToSearchFor",ActiveSheet,lngMoreValuesFound:=2)
を
?fnLngLocateValueCol("valueToSearchFor",ActiveSheet,blnLookUpToBottom:=false)
あなたが列にValueToSearchForを持っている場合は、値で始まるものを探すことにより、同様にそれを見つけることができます。あなたが探してされている
?fnLngLocateValueCol("Value",ActiveSheet,blnLookForPart:=True)
行は、また、オプションのパラメータ(lngRow
)で、それはトップではないとき値1
でlngRow
ためのオプションのパラメータは(もあります。このような行)またはblnLookForPart
、あなたが部品を探しているとき。 -999は、値が見つからないコードです。
これまでのところ、いくつかのVBAアプリケーションで6ヶ月以上働いています。コード内で参照されるルーチンDecrement
は、以下れる
:
Public Sub Decrement(ByRef value_to_decrement As Variant, Optional l_minus As Double = 1)
value_to_decrement = value_to_decrement - l_minus
End Sub
は、すべての特定の列または行のヘッダはありますか? –
あなたの実際の出力は何ですか、あなたは何を期待しましたか?あなたの質問は何ですか、あなたは質問しませんでしたか?ドキュメントの例を見てみましたか?[Range.FindNext](https://msdn.microsoft。com/en-us/vba/excel-vba/articles/range-findnext-method-excel)は正しく動作しますか?それを実装する方法の完全な例があります。 –
@ L.Dutchその1つの特定の列 – Ashok