在Excel中select多行

我使用一个庞大的跟踪器,存储网站的date已经build成。 我试图通过一系列的单元格来确定date是否是今天的date。 我写了一个小小的Excel工作表,使它在执行我的跟踪器之前变得更加简单。

这是我正在与之合作。

Excel截图

问题是只有当今天的date多的时候才select一行。

这是Excel按下button时所做的select。

Excel选择

我如何select多行? (它们可能不是彼此相邻的,将来可能是第1,5,8行)。

' Date Selection Macro ' Goal! - Bring automated cell selection based on date range ' TODO - Create macro to select rows that have a given date range ' TODO - Create a window that allows you to add the given date range ' rather than hard code ' TODO - Export selected rows to an email template in Outlook Sub DateSelection() Dim completionDate As Range Set completionDate = Range("B2:B8") Dim todaysDate As Date todaysDate = Date For Each cell In completionDate If cell = todaysDate Then cell.EntireRow.Select Else 'cell.Font.ColorIndex = 3 End If Next End Sub 

你需要这样的Union

 Sub DateSelection() Dim completionDate As Range Set completionDate = Range("B2:B8") Dim rng As Range Dim todaysDate As Date todaysDate = Date For Each cell In completionDate If cell = todaysDate Then If rng Is Nothing Then Set rng = cell.EntireRow Else Set rng = Union(rng, cell.EntireRow) End If Else 'cell.Font.ColorIndex = 3 End If Next rng.Select End Sub 

但是,您也可以使用filter仅显示具有今天date的行,然后select所有显示的行。 会做同样的:)