How to load table into array, manipulate array and then write array into a new table?

Waimea

Active Member
Joined
Jun 30, 2018
Messages
465
Office Version
  1. 365
Platform
  1. Windows
Hi,

I am trying to load a multiple column table into an array.

1) Load table into array
2) Manipulate several of the columns stored in the array with select case
3) Write back array to spreadsheet

I have 1 working but I am not sure how to do #2 and #3?

VBA Code:
Sub MultiColumnTable_To_Array()

Dim myTable As ListObject
Dim myArray As Variant
Dim x As Long

Set myTable = ActiveSheet.ListObjects("Table1")

myArray = myTable.DataBodyRange

For x = LBound(myArray) To UBound(myArray)
Debug.Print myArray(x, 3)
Next x
  
End Sub

I am trying to use select case myArray(x,6) to manipulate the information in the array but maybe there is a better way?

VBA Code:
Select case myArray(x,6) 
Case Is = 0
Debug.Print ="Off"

Case Is = 0.5
Debug.Print = "On"

End Select

Also, is it possible to loop through a table/databodyrange from bottom to top?

I want to do all the calculations on the information in the array and then write the array back to a new sheet.
 
to be honest I am not quite sure what I am trying to do.
o_O
Doesn't give us much chance then :)
You can band the cases like
VBA Code:
   Select Case myArray(x, 6)
      Case Is <= 0: myArray(x, 10) = "Off"
      Case 0.001 To 0.35: myArray(x, 10) = "Halv efficiency"
      Case 0.351 To 0.5: myArray(x, 10) = "Better"
      Case Else: myArray(x, 10) = "Cool"
   End Select
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi Fluff,

thank you for your reply, you always deliver top notch!

Can I have more then 1 case?

VBA Code:
 Select Case myArray(x, 6)
      Case Is <= 0: myArray(x, 10) = "Off"
      Case 0.001 To 0.35: myArray(x, 10) = "Halv efficiency"
      Case 0.351 To 0.5: myArray(x, 10) = "Better"
      Case Else: myArray(x, 10) = "Cool"
   End Select

And

VBA Code:
 Select Case myArray(x, 4)
      Case Is <= 0: myArray(x, 11) = "Off"
      Case 0.001 To 0.35: myArray(x, 11) = "Low"
      Case 0.351 To 0.5: myArray(x, 11) = "Ok"
      Case Else: myArray(x, 11) = "Top notch"
   End Select

In the same array?
 
Upvote 0
Yes, just put them both inside the loop like
VBA Code:
For x = LBound(myArray) To UBound(myArray)
   Select Case myArray(x, 6)
      Case Is <= 0: myArray(x, 10) = "Off"
      Case 0.001 To 0.35: myArray(x, 10) = "Halv efficiency"
      Case 0.351 To 0.5: myArray(x, 10) = "Better"
      Case Else: myArray(x, 10) = "Cool"
   End Select
   Select Case myArray(x, 4)
      Case Is <= 0: myArray(x, 11) = "Off"
      Case 0.001 To 0.35: myArray(x, 11) = "Low"
      Case 0.351 To 0.5: myArray(x, 11) = "Ok"
      Case Else: myArray(x, 11) = "Top notch"
   End Select
Next x
 
Upvote 0
Hi Fluff,

thank you for your reply! I think that your last post is what I am "trying" to do!

With you code I can stop "trying" and just do it!
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Hi again Fluff,

I am using your code now but I am not sure on how to output the array to my worksheet and/or table?
 
Upvote 0
You can use
VBA Code:
myTable.DataBodyRange = myArray
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,167
Members
448,554
Latest member
Gleisner2

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