简体   繁体   English

仅从 Excel 中的列中选择日期单元格

[英]Select the dates cell only from column in Excel

I am working on excel sheet, in a column having multiple dates and other numbers.我正在处理 excel 表,在具有多个日期和其他数字的列中。 I trying to select the date only and copy it to next column.我试图只选择日期并将其复制到下一列。 I tried to use Find and replace option but its not working, i used the script of KUTOOLS, but its selecting the range of values.我尝试使用查找和替换选项但它不起作用,我使用了 KUTOOLS 的脚本,但它选择了值的范围。 So value falls in the same range of two different values, so could not differentiate.因此值落在两个不同值的同一范围内,因此无法区分。 How to select the cells only date in Excel.如何在Excel中仅选择单元格日期。

Sub FindReplace()
'Update 20150423
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
For Each Rng In WorkRng
    If Rng.Value > 500 Then
        Rng.Value = 0
    End If
Next
End Sub

Below is the excel sheet下面是excel表格

[1]:

You can use the IsDate function on cell.Value (not Value2) to filter if the value is in DATE format.您可以在 cell.Value(不是 Value2)上使用 IsDate 函数来过滤值是否为 DATE 格式。

Dim rng As Range
Set rng = Worksheets(1).Range("A2", "A5")
Dim cell As Range
For Each cell In rng.Cells
  With cell
    If IsDate(cell.Value) Then
      Debug.Print cell.Value
    End If
  End With
Next cell

You could try:你可以试试:

Option Explicit

Sub test()

    Dim LastRow As Long, i As Long

    With ThisWorkbook.Worksheets("Sheet1") '<- Refer to the sheet you want

        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row '<- Find the last row of column A

        For i = 2 To LastRow '<- Loop from row 2 to last row

            If IsDate(.Range("A" & i).Value) Then '<- Check if column A row i is date
                'Code Here
            End If

        Next i

    End With

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM