0

初めてマクロを書いていますが、特定の列の値に基づいて特定の行を選択する方法について質問があります。これまでの私のコードは次のとおりです。

Sub Pipeline()

'Module 3
'Iterating through the Funding Date Column and looking for clients going live within 30 days
'Selecting the rows for each client in that target range
'TODO: Export information into an email template in Outlook
'TODO: Send email to distribution list


Dim fundingDate As range
Set fundingDate = range("M4:M500")

Dim todaysDate As Date
todaysDate = Date

For Each cell In fundingDate
  If cell < todaysDate + 30 Then
   'Need to select the entire row
  Else
  cell.Font.ColorIndex = 3
End If
Next

End Sub
4

1 に答える 1

4

'Need to select the entire rowと置き換えます

cell.entirerow.select

更新 すべてのループなしで必要なものを取得するためのはるかに効率的な方法を次に示します。

For Each cell ...コード内で from toNextを次のように置き換えます。

With fundingDate    
    .AutoFilter 1, "<" & todaysDate + 30        
    .SpecialCells(xlCellTypeVisible).Select 
    'here are your clients going live in next 30 days    
    .AutoFilterMode = False    
End With

30 日以内にクライアントが稼働しない場合に備えて、いくつかのエラー チェックを提供する必要がある場合があります (SpecialCellsメソッドはこれで失敗します)。また、M4 が列ヘッダーでない場合は、範囲が目に見える細胞。

于 2012-10-19T16:29:48.997 に答える