简体   繁体   English

所有单元格的Excel VBA循环功能

[英]Excel VBA Loop function for all cells

Hi i have function to extract from polish personal identity number to birth date. 嗨,我有从波兰人的身份证号码提取到出生日期的功能。 But function only works in current cell . 但是功能仅在当前单元格中有效。 How modify code to execute all cells from A2 - end of worksheet. 如何修改代码以执行A2中的所有单元格-工作表末尾。

工作表

B2 - cell code B2-单元格代码

=IF(VALUE(MID(A2;3;2))>20;"20"&LEWY(A2;2);"19"&LEWY(A2;2))&MOD(MID(A2;3;2);20)&MID(A2;5;2)

I think you are trying to copy the formula from B2 all the way down to the cells in column A that have an input. 我认为您正在尝试将公式从B2一直复制到具有输入的列A中的单元格。 I think this should do what you are looking for. 我认为这应该可以满足您的需求。 I am assuming it is on Sheet 1, if it is not you can alter the code. 我假设它在工作表1中,如果不是,则可以更改代码。

'Defines the parameter to count the rows being used in column A
    lRow = Sheet1.Range("A2").End(xlDown).Row

'Creates the formula for column B
Sheet1.Range("B2") = "=IF(VALUE(MID(A2;3;2))>20;""20""&LEWY(A2;2);""19""&LEWY(A2;2))&MOD(MID(A2;3;2);20)&MID(A2;5;2)"

'Copies and paste the formulas down to the last rows for column B in Sheet 1
    Sheet1.Range("B2").Copy
    Sheet1.Range("B3:B" & lRow).PasteSpecial Paste:=xlPasteFormulas

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM