• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Subscript out of range exception with worksheets

Hi,

I updated a VBA macro file to accommodate new changes.
After making the changes, it was throwing procedure too large error. So, I have divided the code into 2 procedures. But, while accessing the worksheets I'm getting subscript out of range error now in site_tab_uv_tech procedure. Please advice. I'm uploading the necessary files for your review.

Thank You...
 

Attachments

  • att_uverse_blue_macro_ci_07082015.xls
    111 KB · Views: 0
  • att_uverse_blue_template_v9.xls
    53 KB · Views: 0
  • att_uverse_blue_rpt_data.xls
    465.5 KB · Views: 0

Hi !

Here is the Excel worksheet formulas forum !

See in VBA forum with a better explanation, post code between codetags
where error occurs …
 
Hi,

You are facing the error in below line as said workbook wb_output didn't find!!

Code:
last_intv_fcst = Workbooks(wb_output).Worksheets(10).Cells(4, 2)

You are also facing issue due to large subroutine then use like as below..

Code:
With Workbooks(wb_output)
    .Worksheets(3).Cells(7, 6).Value = .Worksheets(10).Cells(4, 2).Value
End With

&
Like as !!

Code:
[A3:C3]=Array("CST","Lock Calls","Adj FC Calls")
 
Thanks for the response Deepak. I'll make modifications to reduce the size of the procedure as you have suggested. But, I'm clueless about "subscript out of range" error. Why I'm getting this error
 
As i said you are facing the issue due to unavailability of workbook wb_output
wb_output holds active work book name. It is throwing error only after executing some of the portion of the procedure.
Please see the below code.
Code:
OutFileName = "c:\work\att_uverse_blue_rpt_macro_output.XLS"
Workbooks.Open Filename:="c:\work\att_uverse_blue_template_v9.xls"
ActiveWorkbook.SaveAs Filename:=OutFileName, FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
Workbooks.Open Filename:=OutFileName
wb_output = ActiveWorkbook.Name
 
oK. But same is not referred in "Sub site_tab_uv_tech()"

It should be like as Sub site_tab_uv_tech(wb_output As String)
& this would be

Code:
'''''''''''''''''''''''''''''''''''''''''''''''''''

site_tab_uv_tech wb_output

'''''''''''''''''''''''''''''''''''''''''''''''''''

There's a lot of things to be optimized in ur code. It seems that there are recorded.

& Change these as well..

Code:
OutFileName = "c:\work\att_uverse_blue_rpt_macro_output.XLS"
        'Workbooks.Open Filename:="\\muraw78\macro\att_uverse_blue_template_v9.xls"
        Workbooks.Open Filename:="c:\work\att_uverse_blue_template_v9.xls"
        ActiveWorkbook.SaveAs Filename:=OutFileName, FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
        ActiveWorkbook.Close 0
        Workbooks.Open Filename:=OutFileName

or

Code:
 OutFileName = "c:\work\att_uverse_blue_rpt_macro_output.XLS"
        'Workbooks.Open Filename:="\\muraw78\macro\att_uverse_blue_template_v9.xls"
        Workbooks.Open Filename:="c:\work\att_uverse_blue_template_v9.xls"
        ActiveWorkbook.SaveAs Filename:=OutFileName, FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
       
        'OutFileName = "c:\work\att_uverse_rpt_macro_output.XLS"
        'Wk.SaveAs Filename:=OutFileName
        'Workbooks.Open Filename:=OutFileName
        wb_output = ActiveWorkbook.Name
        Workbooks(wb_output).Worksheets("Sheet2").Activate
        'Workbooks(wb_output).Worksheets("Sheet2").Delete
        'Workbooks(wb_output).Worksheets("Sheet3").Delete
        wb_output = ActiveWorkbook.Name

 
Hi Deepak,

I'm able to reduce the size of the procedure by using some of the tips you have provided. So, everything is working fine now. Thanks a lot for your support.

Yes. Most of the code is generated by recording macro. so, it has to be optimized. I hope going through this forum will help me in doing that.

Thanks again.
 

Attachments

  • att_uverse_blue_macro_ci_07082015.xls
    95 KB · Views: 0
Back
Top