Error with block variable not set

3

I have the error 91 in VBA with the following code:

Dim i, c, b, a, 

With wsMissingSCM2.ListObjects("tblReportData2")
    .TableStyle = "TableStyleLight6"
    '
    ' LocationColumn
    '
    i = 1
    .ListColumns(i).DataBodyRange.HorizontalAlignment = xlCenter 'ERROR HERE
    .HeaderRowRange.Columns(i).Value = "Missing Item"
    .ListColumns(i).DataBodyRange.ColumnWidth = 14

Any suggestions?

    
asked by Priscila Estala 23.06.2016 в 16:35
source

1 answer

0

When you define the property .DataBodyRange.HorizontalAlignment does not know what object you want to perform since you made another assignment previously, i = 1 , for that reason you get the error With block variable not set (Error 91) :

Change your code, first establishing the properties of wsMissingSCM2.ListObjects("tblReportData2") and then the value of i :

  With wsMissingSCM2.ListObjects("tblReportData2")
    .TableStyle = "TableStyleLight6"
    .ListColumns(i).DataBodyRange.HorizontalAlignment = xlCenter 
    .HeaderRowRange.Columns(i).Value = "Missing Item"
    .ListColumns(i).DataBodyRange.ColumnWidth = 14

    i = 1
    
answered by 23.06.2016 / 16:54
source