VBA range.formula issue (LEN, RIGHT & LEFT)

独自空忆成欢 提交于 2019-12-25 02:23:07

问题


I'm trying to do a VBA code to accomplish 2 things as follows:

Count how many characters there is on cell A1, using the formula LEN(A1) and one the last line, I'm trying to have the formula RIGHT(LEFT(A1;Q1-2);6) on cell J1

Please follow down my VBA code so far:

LR = Cells(Rows.Count, "A").End(xlUp).Row

For i = 1 To LR
    cel = "A" & i
    cel2 = "P" & i
    cel3 = "Q" & i

    Range("P" & i).Formula = "=LEN(" & cel & ")"
    Range("J" & i).Formula = "=RIGHT(LEFT(" & cel & "," & cel3 & "-" & 2 & ")," & 6 & ")"
Next i

It seems something silly what is missing, however, I couldnt manage to solve it so far

Thanks in advance


回答1:


You’re missing a Right, and some other things

Range("J" & i).Formula = "=RIGHT(LEFT(" & cel & "," & cel3 & "-2), 6)"


来源:https://stackoverflow.com/questions/50553724/vba-range-formula-issue-len-right-left

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!