2013-04-24 36 views
0

我有時間值的列:使用公式作爲DO的條件while循環

05:13:32 
05:13:32 
05:13:32 
05:13:32 
05:13:33 
05:13:33 
05:13:34 
05:13:34 
05:13:35 
05:13:35 
05:13:36 
05:13:36 
05:13:36 
05:13:37 
05:13:37 
05:13:38 
05:13:38 
05:13:39 
05:13:39 

這些值在C列

現在:第一點是我開始點尋找下一個比第一個值多2秒的值,這意味着我會找到05:13:34。

我寫了這個代碼,但它不工作,因爲Find功能(什麼:=)不接受varible我宣佈爲x= Activecell.Value + "00:00:2"

Sub sekundenfinder2() 
    Dim sekundo2 As Range 
    Dim x as Integer 
    Range("C153").Select 
    ' //// Here is the Point where I begin to go the colomn down and look for the next value 

    Selection.Activate 
    Set sekundo2 = Range("C:C").Find(What:="x", After:=ActiveCell) 
    sekundo2.Select 
End Sub 

第二個問題:

Activecell.Value給出的值0,21 .......,這意味着Excel會將該值從時間轉換爲數字,但我希望保持這種格式爲「00:00:00」的時間。我試圖將格式更改爲時間,並將其更改爲數字。

有什麼建議嗎?

回答

0
  1. 使用DateAdd加倍
  2. 當您使用x引號內,它不會仍然是一個變量,但chnages爲一個字符串。
  3. 聲明xDate,而不是Integer

這是你想什麼呢?我假設數據是從C1起和C1具有05:13:32

Sub sekundenfinder2() 
    Dim sekundo2 As Range 
    Dim x As Date 

    x = DateAdd("s", 2, Range("C1").Value) 

    Set sekundo2 = Range("C:C").Find(What:=x) 

    If Not sekundo2 Is Nothing Then sekundo2.Select 
End Sub 

enter image description here

+0

非常感謝您!它幫助我 – 2013-04-28 21:09:18

+0

@ i.abdulo接受他的答案,或至少upvote它 – Katana24 2013-05-01 13:59:58