Code to perform formulas to all excel files in a folder not running? -
=i have code performs series of calculations excel (.xls) files in folder destination , places specific number in specified cells (g2, h2, i2, m2 , o1). issue code not respond when click run. doesn't give error. ideas went wrong here?
sub code() dim file string dim wbresults workbook dim long dim mypath string application.screenupdating = false application.displayalerts = false mypath = "c:\location\" file = dir$(mypath & "*.xls*") while (len(file) > 0) set wbresults = workbooks.open(filename:=mypath & file, updatelinks:=0) wbresults.worksheets(split(file, ".")(0)) = .cells(.rows.count, 2).end(xlup).row .range("g2") .formula = "=0" end .range("g3:g" & i) .formula = "=sqrt(((e3-e2)^2)+((f3-f2)^2))" end .range("h2") .formula = "=1" end .range("h3:h" & i) .formula = "=g3+h2" end .range("i2") .formula = "=1" end .range("i3") .formula = "=if(d3>=sum($i$2:i2*2.5+$o$1),1,0)" end .range("i4:i" & i) .formula = "=if(d3>=sum($i$3:i3)*2.5+$o$1,1,0)" end .range("j2:k" & i) .formula = "=if($i2=1,d2,j1)" end .range("k2:k" & i) .formula = "=if($i2=1,h2,k1)" end .range("l2:l" & i) .formula = "=if(i2=1,(j2-j1)/(k2-k1),"")" end .range("m2") .formula = "=0" end .range("m3:m" & i) .formula = "=if(l3="",m2,l3)" end .range("o1") .formula = "=177.5" end end wbresults.close savechanges:=true file = dir wend application.displayalerts = true application.screenupdating = true end sub
comment out these lines debugging purposes. once fixed, un-comment them.
application.screenupdating = false application.displayalerts = false
i see couple problems.
- if file not found
.xls
extension, nothing happen. everywhere have string in formula
""
have double quote""""
with .range("l2:l" & i) .formula = "=if(i2=1,(j2-j1)/(k2-k1),"""")" end
you missing equals sign before
if
on these equationswith .range("j2:k" & i) .formula = "=if($i2=1,d2,j1)" end .range("k2:k" & i) .formula = "=if($i2=1,h2,k1)" end
Comments
Post a Comment