Forum Discussion
CamperVan365
Dec 21, 2022Copper Contributor
Workaround for data table that uses results from another data table.
I set up a data table that depends on optimization results from another data table. Evaluation of the 2nd data table is erratic - some entries are correct, but not all. Is there a way to set i...
CamperVan365
Dec 29, 2022Copper Contributor
Here is the solution that I came up with for my own question.
Perhaps this routine will help someone else with the same problem.
' this VBA routine effectively automates building a data table, and works even if the data table depends on other data table results
' the corner cell is used to pass the independent variable to the rest of the worksheet
' the rest of the top row is used to get the dependent variables ( results ) from the rest of the worksheet
' the rest of the left column contains the list of values to insert sequentially into the corner cell
' the routine sequentially puts each left column entry into the corner cell
' and copies the results from the top row into the row next to the left column entry
' for my application, the corner cell was located at row 7, column 9
' the rest of column 9 ( from row 8 down to row 70 ) contained the list of values to put into the corner cell
' the rest of row 7 ( from column 10 to column 12 ) contained references to get the results I wished to tabulate from the rest of the worksheet
Sub EvaluateDataTable()
cornerRow = 7
cornerColumn = 9
endRow = 70
endColumn = 12
Set cornerCell = Worksheets("Sheet1").Cells(cornerRow, cornerColumn)
For rowCounter = (cornerRow + 1) To endRow
cornerCell.Value = Worksheets("Sheet1").Cells(rowCounter, cornerColumn).Value
For columnCounter = (cornerColumn + 1) To endColumn
Worksheets("Sheet1").Cells(rowCounter, columnCounter).Value = Worksheets("Sheet1").Cells(cornerRow, columnCounter).Value
Next columnCounter
Next rowCounter
End Sub
Perhaps this routine will help someone else with the same problem.
' this VBA routine effectively automates building a data table, and works even if the data table depends on other data table results
' the corner cell is used to pass the independent variable to the rest of the worksheet
' the rest of the top row is used to get the dependent variables ( results ) from the rest of the worksheet
' the rest of the left column contains the list of values to insert sequentially into the corner cell
' the routine sequentially puts each left column entry into the corner cell
' and copies the results from the top row into the row next to the left column entry
' for my application, the corner cell was located at row 7, column 9
' the rest of column 9 ( from row 8 down to row 70 ) contained the list of values to put into the corner cell
' the rest of row 7 ( from column 10 to column 12 ) contained references to get the results I wished to tabulate from the rest of the worksheet
Sub EvaluateDataTable()
cornerRow = 7
cornerColumn = 9
endRow = 70
endColumn = 12
Set cornerCell = Worksheets("Sheet1").Cells(cornerRow, cornerColumn)
For rowCounter = (cornerRow + 1) To endRow
cornerCell.Value = Worksheets("Sheet1").Cells(rowCounter, cornerColumn).Value
For columnCounter = (cornerColumn + 1) To endColumn
Worksheets("Sheet1").Cells(rowCounter, columnCounter).Value = Worksheets("Sheet1").Cells(cornerRow, columnCounter).Value
Next columnCounter
Next rowCounter
End Sub
Elchin_Rashid
Sep 17, 2023Copper Contributor
CamperVan365 then the question is: can you use data from a data table as an independent variable in this macro? Otherwise, you can use Data Table instead of Macro to automatize process and yet get the same result.