excel - Cell reference based on FOR loop index -
here of code:
dim wbx workbook dim wby workbook set wbx = application.workbooks.open("c:\converter\aaa.xls") set wby = application.workbooks.open("c:\converter\bbb.xlsx") = 1 wbx.sheets.count wby.sheets(1).activate range("y" & + 2).select activesheet.range("y" & + 2).formula = "=right(("s" & + 2); 4)"
the problem ("s" & + 2) not recognized cell - vba spits out syntax errors.
your expression "y" & + 2
not yield valid cell reference because concatenate number string. must convert numeric expression string:
"y" & str(i + 2)
what understand comment, assignment should written as:
"=left(s" & trim(str(i + 2)) & "; 4)" ' yields e.g.: =left(s3; 4)
(the left function gets first characters string. assumes cells reference contains strings, or vb converts value string first. , here must use trim(str(i + 2))
because constructing string place formula in cell.)
Comments
Post a Comment