I'm trying to make a script that when I press a button itterates over a table, grabs the first value from the table, sets that value in a cell. Takes another value that is automatically changed (a total) after the previous value was changed and then print that value to a new array in a new worksheet. So the flow I was thinking about is like this.
- Get the percentage
- Set the right cell to that percentage
- Retrieve the total
- Save that total to a new table
And just itterate through that for the entirety of the table.
The code I have right now is the following:
Dim listObj As ListObject, r%, c%
Dim answerList As ListObject
Dim thePercent As ListObject
Dim theTot As ListObject
Dim percentage As Single
Dim totalen As Integer
Set listObj = Sheets("Kostnadskalkylering").ListObjects("Tabell")
Set answerList = Sheets("KostnadsTabell").ListObjects("answerTable")
Set thePercent = Sheets("Artikeldata").ListObjects("thePercentage")
Set theTot = Sheets("Artikeldata").ListObjects("theTotal")
For c = 1 To listObj.ListColumns.Count For r = 1 To listObj.ListRows.Count percentage = listObj.DataBodyRange.Cells(r, c).Value thePercent.Value = percentage totalen = theTot.Value answerList.DataBodyRange.Cells(r, c).Value = totalen Next
Next
Firstly I would like for answerList to also be Listobject, r%, c% but then I get an error for duplicated values. And with the code I currently use I get an out of bounds error. Could someone please help me spot what I am doing wrong. Thanks in advance