i encounter worksheet loop issues.
i trying develop macro can replace division error in every worksheet. replacement part of macro works, if apply first worksheet. once added workbook looping, points out line "currentws.cells(i, j).formula = newformula" not correct anymore. , thinking because looping through worksheet, , activesheet thrown off?
any advise appreciated! thanks!
sub replacingformula2() dim currentws worksheet dim allws worksheet dim temp string dim temp2 string dim divider string dim newformula string dim colnum long dim integer dim j integer dim slashposition integer application.screenupdating = false application.enableevents = false set currentws = activesheet each allws in activeworkbook.worksheets ' loop works appropriate if 1 worksheet rownum = currentws.cells(rows.count, "b").end(xlup).row = 1 rownum colnum = currentws.cells(i, columns.count).end(xltoleft).column j = 3 colnum temp = currentws.cells(i, j).formula slashposition = instr(temp, "/") if (slashposition > 0) divider = mid(temp, slashposition + 1) temp2 = mid(temp, 2) newformula = "=if(" & divider & "=0,0," & temp2 & ")" ' line gives error after adding loop through workbook currentws.cells(i, j).formula = newformula end if next j next next currentws.activate application.enableevents = true end sub
Comments
Post a Comment