I have a table in a worksheet that I want to iterate over and change the value of using a function I had set up. The function just calls on multiple Replace functions to change the strings.
My question is how do I iterate over the values in the table only?
I was able to do it with columns using the following code:
For Each cell In Sheets("RawData").ListObjects("RawTable").ListColumns("REQUESTNAME").DataBodyRange.Cells
cell.Value = decodeEnt(cell.Value)
Next
But how do I modify that code to make it iterate through the rows as well? I tried using a combination of ListRows and ListColumns, but didn't know where to go afterwads. Here is where I got to before I was unsure:
Dim listObj As ListObject
Set listObj = Sheets("RawData").ListObjects("RawTable")
For Each tableRow In listObj.ListRows
For Each tableCol In listObj.ListColumns
' Would using intersect work here?
' listObj.Cell.Value = decodeEnt(cell.Value)
Next
Any help is appreciated.
I think you can't use a variant iteration like that, you have to use indexed iteration. Something like this (untested):
Dim listObj As ListObject, r%, c%
Set listObj = Sheets("RawData").ListObjects("RawTable")
For c = 1 To listObj.ListColumns.Count
For r = 1 To listObj.ListRows.Count
listObj.DataBodyRange.Cells(r, c).Value = decodeEnt(listObj.DataBodyRange.Cells(r, c).Value)
Next
Next
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With