GeoTechnical データのワークシートを読み取り、特定の行の値に基づいてデータを選択し、その行を選択して、ワークシートの最後まで読み取りを続けるマクロを作成する必要があります。すべての行を選択したら、それらの行を新しいワークシートにコピーする必要があります。私は約 10 年間 VBA を行っていないので、元に戻そうとしています。
たとえば、マクロにワークシートを読み取らせたいのですが、列「I」の特定の行に「Run」という単語が含まれている場合、その行から A:AM を選択したいと考えています。最後までワークシートを読み続けます。ワークシートのデータ グループ間に最大 10 ~ 15 行の空白行が存在する場合があるため、ドキュメントの最後は注意が必要です。空白行が 25 行を超える場合、ドキュメントは最後になります。すべてを選択したら、選択内容をコピーして新しいワークシートに貼り付ける必要があります。これまでのコードは次のとおりですが、選択できません。
Option Explicit
Sub GeoTechDB()
Dim x As String
Dim BlankCount As Integer
' Select first line of data.
Range("I2").Select
' Set search variable value and counter.
x = "Run"
BlankCount = 0
' Set Do loop to read cell value, increment or reset counter and stop loop at end 'document when there
' is more then 25 blank cells in column "I", copy final selection
Do Until BlankCount > 25
' Check active cell for search value "Run".
If ActiveCell.Value = x Then
'select the range of data when "Run" is found
ActiveCell.Range("A:AM").Select
'set counter to 0
BlankCount = 0
'Step down 1 row from present location
ActiveCell.Offset(1, 0).Select
Else
'Step down 1 row from present location
ActiveCell.Offset(1, 0).Select
'if cell is empty then increment the counter
BlankCount = BlankCount + 1
End If
Loop
End Sub