excel - Issues with Multiple Runtime errors: updated code - still having issues -


thank far - appreciated!! still having issues

i new user of vba in excel , i'm sure answer simple.

i have gone through lots of attempts @ fixing reading existing questions each time different error , have not been able fix issue.

as such have gone through many iterations of code trying fix problems welcome advice on how proceed.

apologies if don't format / ask question appropriately.

background

i have 2 excel files: wb1) 1 sheet table of company names , ids (list changes every week) wb2) workbook multiple tabs template.

for every company listed in wb1 need copy company name , id appropriate cell in wb2 , save company name & date.

as above have gone through many iterations , had below still not getting work.

the various errors have been getting depending on how amend code runtime error 5, runtime error 438, compile error , possibly others didn't write down.

current issue:

if macro saved in wb1 - macro runs , creates first workbook "system error& h800401a8 (-2147221080)

if macro saved in personal macro workbook - "script out of range". appears break @ line set tb1 = wb1.sheets("sheet1").listobjects("table1")

i welcome advice on how fix problem , thank in advance.

this code stands:

    option explicit      sub createstat()       dim companyname string     dim companyid string     dim z long     dim wb1 workbook     dim wb2 workbook     dim tb1 listobject     dim long       set wb1 = **struggling this. want reference workbook has  table in being used draw through companyname , companyid.  open.  table formatted table starting a1 headers in row a**. (errors come when set thisworkbook)     set wb2 = workbooks.open("c:\users\yyy\documents\statements\srtemplate.xlsx")     set tb1 = wb1.sheets("sheet1").listobjects("table1")       application.screenupdating = false     application.displayalerts = false      wb1.activate      sheets("sheet1").select      z = tb1.databodyrange.rows.count       = 2 z + 1       companyid = tb1.databodyrange.cells(i, 1)     companyname = tb1.databodyrange.cells(i, 2)      wb2.activate      wb2.sheets("reconciliation").range("d3").value = companyname     wb2.sheets("reconciliation").range("m3").value = companyid      chdir "c:\users\hannah.wyld\documents\statements\"         activeworkbook.saveas filename:= _     "c:\users\yyy\documents\statements\" & companyname & " " & format(date, "mmm") & ".xlsx", fileformat:=xlopenxmlworkbook, createbackup:=false       windows(companyname & " " & format(date, "mmm") & ".xlsx").close     wb2.activate     wb2.close      wb1.activate      next      end sub 


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -