How to write from an array to another array in excel vba

ساخت وبلاگ

Vote count: 0

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.

  1. Get the percentage
  2. Set the right cell to that percentage
  3. Retrieve the total
  4. 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

asked 20 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 388 تاريخ : شنبه 14 اسفند 1395 ساعت: 13:43