excel - Appending values to an array while scraping -


i'm pretty new vba don't know how use arrays properly.

i trying add new values array i'm scraping documents don't know how this..

  • the values have being scraped 275 documents.
  • i tried write values immediate window ran, worked well, 200 lines.
  • i append 4 lines every time runs through file,
  • one line each variable rfr, chief ,etc....

the code:

sub deletenotopssheet() dim fpath string dim fname string dim wb workbook dim ws worksheet dim xws worksheet dim rfr string, chief string, yard string, tp string dim output thisworkbook  dim long dim spath string 'which folder? fpath = "\\hofiler1\fileserver\users\achan\documents\scrape\manning\sep" 'check if slash included if right(fpath, 1) <> "\'" fpath = fpath & "\" end if 'check xlsm files fname = dir(fpath & "*.xls") 'turn of screen application.screenupdating = false application.displayalerts = false 'loop until run out of files  while fname <> "" 'open workbook set wb = workbooks.open(fpath & fname)  each xws in wb.worksheets  if xws.name = "ops sheet" '--> getting object required error here      rfr = left(activeworkbook.name, 11) & " - reefer foreman: " & worksheetfunction.counta(range("p42"))     chief = left(activeworkbook.name, 11) & " - chief foreman: " & worksheetfunction.counta(range("v78"))     yard = left(activeworkbook.name, 11) & " - yard foreman: " & worksheetfunction.counta(range("ab74:ab81"))     tp = left(activeworkbook.name, 11) & " - tpc foreman: " & worksheetfunction.counta(range("ab68"))      'need here: append these values sheet1 on thisworkbook     'debug.print rfr     'debug.print chief     'debug.print yard     'debug.print tp  end if wb.save wb.close true  next  application.displayalerts = true  'delete others  'savechanges:=true, filename:=newname 'increment count feedback = + 1 'get next file name fname = dir() loop 'turn screen on application.screenupdating = true 'give feedback msgbox "all done." & vbnewline & "number of files changed: " & i, vbokonly, "run complete" end sub 

to write data sheet1 suggest:

a) declare variable keep track of row writing to

dim rowout long 

b) every time go write new row, increment variable

c) either write each item single column, new row each item

rowout = rowout + 1: thisworkbook.worksheets("sheet1").cells(rowout, "a").value = rfr rowout = rowout + 1: thisworkbook.worksheets("sheet1").cells(rowout, "a").value = chief rowout = rowout + 1: thisworkbook.worksheets("sheet1").cells(rowout, "a").value = yard rowout = rowout + 1: thisworkbook.worksheets("sheet1").cells(rowout, "a").value = tp 

or write each item different column on same row

rowout = rowout + 1 thisworkbook.worksheets("sheet1").cells(rowout, "a").value = rfr thisworkbook.worksheets("sheet1").cells(rowout, "b").value = chief thisworkbook.worksheets("sheet1").cells(rowout, "c").value = yard thisworkbook.worksheets("sheet1").cells(rowout, "d").value = tp 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -