[英]Excel Macro: Selecting a specific Row based on column date
我正在編寫我的第一個宏,並且對如何根據特定列中的值選擇特定行存在疑問。 到目前為止,這是我的代碼:
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
替換'Need to select the entire row
cell.entirerow.select
更新這是一種無需所有循環即可更高效地獲取所需內容的方法。
在您的代碼中,使用以下方法從“ For Each cell ...
替換為Next
:
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不是您的列標題,則可能需要調整范圍的拾取方式可見細胞。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.