store a range

starl

Administrator
Joined
Aug 16, 2002
Messages
5,984
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
I need to store the values of a range to be placed at a later time.
What do I store them in? an array? So I need to create a loop to go through the range and place them in there???

thanks
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Jim North

MrExcel MVP
Joined
Jun 20, 2002
Messages
791
store them for how long? Until the macro ends?

A STATIC variable will hold data while a DIMed variable has a limited life.

Please explain what you are trying to do.
 

starl

Administrator
Joined
Aug 16, 2002
Messages
5,984
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
Well, the procedure will call other procedures, but ultimately it'll be the top procedure and the variables only need to last that long.

As to what I'm doing: I have a group of worksheets which will be deleted - but I need to store some information on those sheets to put in new sheets that will created.
Got a better idea? Sample code???? ANYTHING to make this easier :biggrin:
 
Joined
Feb 8, 2002
Messages
3,076
Office Version
  1. 365
Platform
  1. Windows
Hey Starl,

You can create an array from a range easily:

MyData = Range("A2:Z1000").Value

Then, later you could use:
For i = 1 to UBound(MyData, 1)
For j = 1 to UBound(MyData, 2)
debug.Print MyData(i, j)
Next j
Next i

If you need to store the array, you can store the entire array in a workbook name:
Names.Add Name:="MyName", RefersTo:=MyData

Limits in Excel 2000 or earlier on storing a range in a name: 256 columns and not more than 5461 elements total. In XL2002 or later, the size is limited only by memory.

Credit to Bullen's "Excel 2002 VBA"

Bill
 

starl

Administrator
Joined
Aug 16, 2002
Messages
5,984
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
MyData is of what type variable?
 

Forum statistics

Threads
1,144,311
Messages
5,723,645
Members
422,508
Latest member
Lordkit1

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
Top