Excel VBA は初めてで、作業プロセスを高速化するための便利なマクロを作成するのはこれが初めての試みです。
私がやろうとしていること
約 15,000 行 x 約 15 列のデータ ファイルがあります。マクロで実行したいのは、別のシートのボタンを押すと、コードはそのシートの特定のセルに入力した文字列を取得し、すべてのデータを含むシートに移動してから、検索を使用することです列の 1 つで関数を実行して、定義した文字列のすべてのインスタンスを検索します。
文字列のすべてのインスタンスが見つかったら、対応する行をコピーして、マクロを実行したシートに貼り付けます。
明確にするために、文字列を見つけたい列には、人々が入力した説明が含まれています。見るべき単語は1つだけではありません。そのため、検索機能を使用しようとしています。
これまでの私の試み:
Sub FindTextBasicData()
'Define variables
Dim sourceSht As Worksheet
Dim outputSht As Worksheet
Dim strSearch As String
Dim searchRange As Range
Dim outputRange As Range
'Set the sheet variables to those present in the workbook
Set sourceSht = Sheets("Basic Data")
Set outputSht = Sheets("Output")
'Set the value of the string variable to the contents of cell C2 in the output sheet
strSearch = outputSht.Range("C2")
'Set the range variable to the range in the data sheet that I want to check
Set searchRange = sourceSht.Range("C6:C15448")
'Use the Find function to look through the range I defined and select all rows where the
'string variable can be found, setting the second range variable to these values
Set outputRange =searchRange.Find(What:=strSearch, After:=.Cells(3, 6), LookIn:=xlFormulas, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False).EntireRow
'Copy the results of the Find function to the clipboard
outputRange.Copy
'Select the 5th row of the output sheet as the location to paste the data, and then paste
outputSht.Select
Rows(5).Select
ActiveSheet.Paste
End Sub
私は間違いなく検索機能で何か間違ったことをしていることを知っていますが、私はそれを理解することはできません - 私の問題は、私が思っていることをしないという点でAfterパラメータにあると思います(セルC6を参照) Find from? の使用を開始する場所として)。Ozgrid の検索機能のガイドを見てみましたが、もっと混乱したと思います。
このマクロを正しく機能させることができれば、この 15000 レコードに対して行う必要があるデータの分析を大幅に合理化するために、マクロを多用できるようになります。これについての助けをいただければ幸いです。もちろん、私が何かを十分に説明していない場合は、喜んで明確にします。