[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『日付の検索がうまくできません。どうすればよいでしょうか?』(シマダ)
A1セルに、2018/7/1を入力しています。
その下セルA2には、=A1+1 として(表示は、2018/7/2)
これを、セルA31まで =A1+30 としています。
そこで、以下のVBAで本日の日付をA列で検索をし、そのセルを選択したいのですが、検索できません。どうすれば、できるのでしょうか?教えてください。
また、このような日付表記では、できないのでしょうか?
Sub Sample()
Dim FoundCell As Range
Dim a As String
a = Date '今日の日付
Set FoundCell = Range("A:A").Find(What:=DateValue("a"), LookIn:=xlFormulas)
If FoundCell Is Nothing Then GoTo Sub10 Else ActiveCell.Select
End If
Sub10:
End Sub
< 使用 Excel:Excel2013、使用 OS:Windows7 >
Sub Sample() Dim FoundCell As Range
Set FoundCell = Range("A:A").Find(What:=Format(Date, "yyyy/m/d"), LookIn:=xlValues) If FoundCell Is Nothing Then Exit Sub
FoundCell.Select End Sub (???) 2018/07/10(火) 18:10
Set FoundCell = Range("A:A").Find(What:= Date, LookIn:=xlFormulas) でできませんか?
ダメなら Dim x x=Application.match(clng(date),columns("a"),0) If Isnumeric(x) then cells(x,1).select (seiya) 2018/07/10(火) 19:23
Sub Samole()
Dim FoundCell As Range Dim a As Date a = Date Set FoundCell = Range("A:A").Find(What:=a, LookIn:=xlValues) If FoundCell Is Nothing Then Exit Sub FoundCell.Select End Sub (hatena) 2018/07/10(火) 19:38
・・で、どうやって(どの案で)解決したんですか?
そこが大事なとこなんですけども・・
(半平太) 2018/07/10(火) 20:24
Sub Sample()
Dim c As Range
Dim d As Range
Dim e As String
'Stop
Range("A11:A46").ClearContents
Range("A1").Value = Format(Time, "hh:mm:ss")
Range("D9").Value = Year(Now)
Range("D10").Value = Month(Now)
Range("D1").Formula = "=TODAY()" '今日の日付
Range("C1").NumberFormatLocal = "yyyy/m/d"
Range("D1").NumberFormatLocal = "yyyy/m/d"
Range("B:B").NumberFormatLocal = "yyyy/m/d" Set c = Columns("B").Find(What:=Range("C1").Value, LookIn:=xlValues, LookAt:=xlWhole) If c Is Nothing Then Exit Sub
c.Select
ActiveCell.Offset(0, 1).Select
Sub5:
If ActiveCell.Value = "休" Then ActiveCell.Offset(1, 0).Select
GoTo Sub5
Else
ActiveCell.Offset(0, -2) = "1" ActiveCell.Offset(1, 0).Select
End If
Sub10:
If ActiveCell.Value = "休" Then ActiveCell.Offset(1, 0).Select
GoTo Sub10
Else
ActiveCell.Offset(0, -1).Select ActiveCell.Offset(0, -1) = "2" ActiveCell.Offset(1, 1).Select
End If
Sub20:
If ActiveCell.Value = "休" Then ActiveCell.Offset(1, 0).Select
GoTo Sub20
Else
ActiveCell.Offset(0, -1).Select ActiveCell.Offset(0, -1) = "3" ActiveCell.Offset(1, 1).Select
End If
Sub30:
If ActiveCell.Value = "休" Then ActiveCell.Offset(1, 0).Select
GoTo Sub30
Else
ActiveCell.Offset(0, -1).Select ActiveCell.Offset(0, -1) = "4"
End If
Set d = Columns("B").Find(What:=Range("D1").Value, LookIn:=xlValues, LookAt:=xlWhole) If d Is Nothing Then Exit Sub
d.Select
ActiveCell.Offset(0, -1).Select
If ActiveCell.Value = "" Then
Range("A11:A46").ClearContents
ActiveSheet.Range("E1") = ""
ActiveSheet.Range("A1") = ""
ActiveSheet.Range("A1").Select
GoTo Sub40
Else
e = ActiveCell.Value
Sheets("sheet1").Select
ActiveSheet.Range("E1") = e
ActiveSheet.Range("A1").Select
End If
Sub40:
End Sub
(シマダ) 2018/07/10(火) 22:20
当初の説明と随分違いますね。
そちらは、こんな状態では全然ないですよね。 ↓ >A1セルに、2018/7/1を入力しています。 >その下セルA2には、=A1+1 として(表示は、2018/7/2)
また、この話とかみ合う部分もない。 ↓ >しかし、回答くださったものだと、ヒットせずに終わってしまいます。
それでいて、これで解決? ↓ >(???)さんのものを活用しました。
私には訳が分かりません。
まぁ、シマダさんが解決できたってことなので、それでいいことにします。
多分、またトラブルに陥るでしょうが、その時また質問に来てください。
(半平太) 2018/07/10(火) 23:44
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.