お蔵入り

変数の宣言はあっていますか?またこのコーディングについて解説がいただけたらうれしいです。

Dim lastRow As Long
Dim t_day As Variant
Dim serch As Variant
Dim result As Variant
Dim d_count As Long
Dim r_count As Long

   
   lastRow = Range("G" & Rows.Count).End(xlUp).Row
   For Each t_day In Range("G12:G" & lastRow)
       If t_day <> "" Then
       If IsDate(t_day) Then
           serch = Application.Text(t_day, Range("D12").NumberFormat)
           Set result = Columns("D:D").Find( _
                       What:=serch, _
                       LookIn:=xlValues, _
                       LookAt:=xlWhole, _
                       SearchOrder:=xlByRows, _
                       SearchDirection:=xlNext, _
                       MatchCase:=False, MatchByte:=False)
           
           If Not result Is Nothing Then
               d_count = 0
               r_count = 0
               Do
                   If Range("F" & result.Row - r_count) <> "★" Then _
                           d_count = d_count + 1
                   If d_count = 4 Then Exit Do
                   r_count = r_count + 1
               Loop
               Range("H" & t_day.Row) = Range("D" & result.Row - r_count)
           End If
           
       End If
       End If
   Next
   Set result = Nothing
End Sub

2008-06-16 01:11の質問
この質問は、30日間解決しなかったために自動的に質問が一旦閉じられました。
Ads By Google

回答

まだ回答がありません

コメント(2)

#1.  BLUEPIXY
2008-06-16 04:18:30

変数宣言は、特に問題ないと思います。
Dim i,j,k
とかの宣言もヴァリアントになるというだけでのことで、特別問題があるというわけではありません。
例えば、整数であるなら、
Dim i as integer
の様により特定した型の方が効率(やスピード)が良いというだけです。

2008-06-22 13:37:56

BLUEPIXYさんの言う通り、変数宣言は問題ありません。データ型を最適にしたいというならば、serchとresultは、Range型で宣言しておくと良いかと思います。
Dim serch As Range

t_dayは、セルに何が入力されているか分からないので、Variant型で構わないと思います。
(String型でも問題はないですが…)

コーディングの解説って各行に対する説明が欲しいということなのでしょうか?

トラックバック

トラックバックURL: