XL2010 Static Variable not Being Static

Klevins11

New Member
Joined
May 15, 2015
Messages
6
I create a range using the UsedRange of the ActiveSheet and then select at random a cell within this range. After this (code not shown) it transfers whatever is in this cell to another cell outside of the used range. When ran again, the UsedRange is updated to the current used range instead of the original one. I thought declaring the variables as static at the beginning would lock the initial used range. Please advise.
Code:
Static row_min As Integer
Static row_max As Integer
Static col_min As Integer
Static col_max As Integer
Dim actv_row As Integer
Dim actv_col As Integer
Dim actv_cell As String

row_min = ActiveSheet.UsedRange.Row
row_max = row_min + ActiveSheet.UsedRange.Rows.Count - 1
col_min = ActiveSheet.UsedRange.Column
col_max = col_min + ActiveSheet.UsedRange.Columns.Count - 1
actv_row = Int((row_max - row_min + 1) * Rnd + row_min)
actv_col = Int((col_max - col_min + 1) * Rnd + col_min)


ActiveSheet.Cells(actv_row, actv_col).Select
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
No, static means they're remembered in the sub for use next time unless you overwrite them
 
Upvote 0

Forum statistics

Threads
1,215,456
Messages
6,124,940
Members
449,197
Latest member
k_bs

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