excel - How to use double For loop in VBA? -


i trying define file path , file name using loop.

after doing main action (that count of rows in example), need path next file path , next file name @ same time , main action (rows count).

but have problems using next, because order trying use wrong. maybe can this? in advance!

sub countrows()     dim wbsource workbook, wbdest workbook     dim wssource worksheet, wsdest worksheet     dim strfolder string, strfile string     dim lngnextrow long, lngrowcount long     dim lastrow     dim cl range     dim cell range      lastrow = wsdest.cells.find("*", searchorder:=xlbyrows, searchdirection:=xlprevious).row     lngnextrow = wsdest.range("f" & wsdest.rows.count).end(xlup).row + 1      'here define path file     each cl in wsdest.range("g11:g" & lastrow)         strfolder = cl.value          'here define file name         each cell in wsdest.range("c11:c" & lastrow)             strfile = cell.value              'here happens count of row or other action             set wbsource = workbooks.open(filename:=strfolder & strfile)             set wssource = wbsource.worksheets(1)             lngrowcount = wssource.usedrange.rows.count             wsdest.cells(lngnextrow, "f").value = lngrowcount - 1             wbsource.close savechanges:=false             lngnextrow = lngnextrow + 1          'then need pass next path & next file name         next cell     next cl  end sub 

replace 2-loop structure :

for each cl in wsdest.range("g11:g" & lastrow)      strfolder = cl.value     strfile = wsdest.range("g" & cl.row).value      set wbsource = workbooks.open(filename:=strfolder & strfile)     set wssource = wbsource.worksheets(1)     lngrowcount = wssource.usedrange.rows.count     wsdest.cells(lngnextrow, "f").value = lngrowcount - 1     wbsource.close savechanges:=false     lngnextrow = lngnextrow + 1  next cl 

it open file on each line folder on same line


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -