Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Com Error with macro within for loop due to creating new workbook in the loop
So I have three files right now, 1. Template file with the rater, which performs calculations, and two files with data that gets copied to the rater.

I wrote a code that loops through the files assigns them to a work book copies the data from the work book to the rater, runs the macro to perform the calculations, and copies the output column back to the work book/save/close.

It works fine if I run it in pieces but click on the worksheets. however when I try to run it within the loop it gives me a com_error.
This leads me to believe that when I create the new workbook it makes the new workbook the active workbook.
#macros to run

for file_name in filenames:


    comp_data=wb.sheets("Data for Rater").range("copy_range").value
    rater.sheets("Batch Rater").range("b23").value=comp_data


    comp_premium=rater.sheets("Batch Rater").range("premium_copy_py").value
    #wb.sheets("Batch Rater").range("AQ23").options(transpose=True).value=test
    if file_name=="cien_cova_roofage_rooftype.xlsx":
        wb.sheets("All Company Premium").range("AQ67202").options(transpose=True).value=comp_premium
    elif file_name=='cien_cova_yearbuilt.xlsx':
        wb.sheets("All Company Premium").range("AQ12002").options(transpose=True).value=comp_premium



Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Arrange list of tuple using loop batchenr 7 158 Jun-16-2019, 03:24 PM
Last Post: Abdullah
  Why doesn't my loop work correctly? (problem with a break statement) steckinreinhart619 2 141 Jun-11-2019, 10:02 AM
Last Post: steckinreinhart619
  Loop through array items dynamically in a certain format bhojendra 3 107 Jun-11-2019, 03:37 AM
Last Post: micseydel
  change to loop amirliker 3 133 Jun-06-2019, 01:08 PM
Last Post: heiner55
  while loop ef26 5 187 May-27-2019, 01:25 PM
Last Post: DeaD_EyE
  my function is stuck on loop - even when it not supposed to be korenron 2 216 May-26-2019, 12:31 PM
Last Post: korenron
  Working on my FOR loop wilsonrivas 1 299 May-24-2019, 04:05 PM
Last Post: heiner55
  learning to while loop iofhua 7 158 May-24-2019, 09:46 AM
Last Post: DarkCraftPlayz
  Server infinite loop input from user tomislav91 1 304 May-23-2019, 02:18 PM
Last Post: heiner55
  Need help parallelizing while loop Smurfi 0 117 May-21-2019, 01:45 PM
Last Post: Smurfi

Forum Jump:

Users browsing this thread: 1 Guest(s)