Excel VBA - 不使用相同公式自动填充整个表列的代码

时间:2016-06-13 17:22:52

标签: excel vba excel-vba macros

我正在处理一个表对象,我需要代码来对第3列进行排序,并更改日期(mmm-d)读取“Jan-0”的任何出现。因为我正在使用表对象,所以每次我尝试引用列“Clock Out”(E)时,其格式如下:

m / d / yyy hh:mm:ss AM / PM,

使用.formulaR1C1代码,它将第3列中的每个单元格更改为该公式。这是一个问题,因为我希望列D(日期)由列D(时钟输入)中的值确定,或者,如果列D为空,那么我希望它由列E中的值填充(时钟输出)。

没有列D和列E都为空的情况。

Accept-Ranges: bytes
Access-Control-Allow-Methods: *
Access-Control-Allow-Origin: *
Connection: Keep-Alive
Content-Encoding: gzip
Content-Length: 497
Content-Type: text/html
Date: Mon, 13 Jun 2016 17:11:06 GMT
Etag: "352-5352bf8ecde14-gzip"
Keep-Alive: timeout=5, max=100
Last-Modified: Mon, 13 Jun 2016 17:10:59 GMT
Server: Apache/2.4.10 (Raspbian)
Vary: Accept-Encoding
access-control-allow-credentials: true
access-control-allow-headers: Accept,Accept-Charset,Accept-Encoding,Accept-Language,Connection,Content-Type,Cookie,DNT,Host,Keep-Alive,Origin,Referer,User-Agent,X-CSRF-Token,X-Requested-With

1 个答案:

答案 0 :(得分:2)

我明白了,这就是诀窍:

For i = erow To 1 Step -1
    If Cells(i, 3).Text = "Jan-0" Then
       Application.AutoCorrect.AutoFillFormulasInLists = False '<~~ THIS LINE DID IT 
       Cells(i, 3).Value = "=TEXT([@[Clock Out]],""mmm-d"")"
    End If
Next i