Data Table Ranges as Dimensions

tfortier

New Member
Joined
Dec 10, 2019
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I am trying to use VBA to activate a what-if analysis data table and to set up the row and column two factor variable. DT_MFG_Act - is a range name in the Workbook. intJSRow, intActCol, and intGACRow are all integers that represent a row or a column number. This worked yesterday when I originally wrote it but now I am getting the runtime error1004 Range of object global failed. The error occurs on the last line which is setting up the table. I believe it has something to do with my range names being variables. I'd really like to keep them as variables because the column number will vary based on the month we are in and the row number will change based on the worksheet that I call.


Can anyone help?? Thanks in advance.

' Select the range that will house the data table.
Range("DT_MFG_Act").Select

'set up the "result cell" in the data Table
ActiveCell.FormulaR1C1 = "=+MFG!R" & intTotalRowMFG & "C" & intTotalColAct

'Select the range again
Range("DT_MFG_Act").Select

'This is where the error happens
Selection.Table RowInput:=Range(Cells(intJSRow, intActCol)), ColumnInput:=Range(Cells(intGACRow, intActCol))
 
Welcome to the Forum

You need Cells(), rather than Range(Cells()). You also don't need to use Select.

VBA Code:
With Range("DT_MFG_Act")
    .Cells(1, 1).FormulaR1C1 = "=MFG!R" & intTotalRowMFG & "C" & intTotalColAct
    .Table RowInput:=Cells(intJSRow, intActCol), ColumnInput:=Cells(intGACRow, intActCol)
End With

I assume RowInput and ColumnInput are on the same worksheet as Range("DT_MFG_Act"), rather than on Worksheets("MFG")?
 
Upvote 0
Welcome to the Forum

You need Cells(), rather than Range(Cells()). You also don't need to use Select.

VBA Code:
With Range("DT_MFG_Act")
    .Cells(1, 1).FormulaR1C1 = "=MFG!R" & intTotalRowMFG & "C" & intTotalColAct
    .Table RowInput:=Cells(intJSRow, intActCol), ColumnInput:=Cells(intGACRow, intActCol)
End With

I assume RowInput and ColumnInput are on the same worksheet as Range("DT_MFG_Act"), rather than on Worksheets("MFG")?
That worked great!! Thank you so much for the tip! You are amazing!
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top