简体   繁体   中英

Select the dates cell only from column in Excel

I am working on excel sheet, in a column having multiple dates and other numbers. 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. So value falls in the same range of two different values, so could not differentiate. How to select the cells only date in 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

[1]:

You can use the IsDate function on cell.Value (not Value2) to filter if the value is in DATE format.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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