[英]Select the dates cell only from column in Excel
我正在處理 excel 表,在具有多個日期和其他數字的列中。 我試圖只選擇日期並將其復制到下一列。 我嘗試使用查找和替換選項但它不起作用,我使用了 KUTOOLS 的腳本,但它選擇了值的范圍。 因此值落在兩個不同值的同一范圍內,因此無法區分。 如何在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
下面是excel表格
您可以在 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
你可以試試:
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.