用vbainput函数:用i行连接列

我想从string中提取date:

星期二2月25日16:13:15 PST 2016

我的macros进入函数,但是,它不正确连接我的列,所以这将是特定的行号。 相反,我得到这个:

= CONCATENATE(MID(“J”&i,5,6),“,”,RIGHT(“J”&i,4))

请帮我连接。 谢谢

Sub FormatDate() FinalRow = Cells(Rows.Count, 12).End(xlUp).Row For i = 3 To FinalRow Cells(i, 12).Formula = "=CONCATENATE(MID(""B"" & i,5,6),"","",RIGHT(""B"" & i,4))" Next i End Sub 

这里有一个不同的方法,导致一个“真实”的date,你可以在计算中使用,而不需要在单元格中input公式。 我的格式与公式的结果相同,但是可以根据需要进行格式化。


 Option Explicit Sub FormatDate() Dim FinalRow As Long Dim V As Variant Dim I As Long FinalRow = Cells(Rows.Count, 12).End(xlUp).Row For I = 3 To FinalRow V = Split(Cells(I, "B")) V(1) = Month(DateValue(V(1) & " 01")) 'Change month string into number. Cells(I, 12) = DateSerial(V(5), V(1), V(2)) Cells(I, 12).NumberFormat = "mmm dd yyyy" Next I End Sub 

还有其他方式处理date:


 For I = 3 To FinalRow V = Split(Cells(I, "B")) Cells(I, 12) = DateValue(V(1) & " " & V(2) & " " & V(5)) Cells(I, 12).NumberFormat = "mmm dd yyyy" Next I 

你在错误的地方有你的报价:

 Cells(i, 12).Formula = "=CONCATENATE(MID(B" & i & ",5,6),"","",RIGHT(B" & i & ",4))"