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

更新 这是一种更有效的方法,无需所有循环即可获得所需内容。

在您的代码中将 from 替换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 不是您的列标题,您可能需要调整范围如何获取可见细胞。

于 2012-10-19T16:29:48.997 回答