Creating Variable Range and inserting it to complete calculations

DonEB

Board Regular
Joined
Apr 26, 2016
Messages
133
Office Version
  1. 2019
Platform
  1. Windows
Parts of my program (i.e., ranges) change depending on amount of data that is keyed in. I know the ranges minimum size (E6:I10) and the ranges maximum size of (E6:X25).

Based on previous research, I know how to identify last column and I know how to identify the last row. What I'm having difficulty with is determining how to utilize this information to create the dynamic range that can be inserted into another formula.

What I would like to be able to do is replace the "E6:K12" (fixed range below) with code that will allow it to be flexible and dynamically change as the data changes from month to month or quarter to quarter.

Any attempt I've made has resulting in one type of error or another.

With Sheets("CommonData2")
ColP = .Cells(6, Columns.Count).End(xlToLeft).Column

'Note: using column "C" does provide the best results for determining "last row". Other columns may contain a "0" thus giving an unintended/undesirable result.
LastRow = .Range("C6:C35").Find(What:="*", After:=.Range("C6:C35").Cells(1, 1), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

'Example of fixed range
rRange = ("E6:K12")
'rRange = ????????? '<=== Trying to create the dynamic range to insert into the variable and use in the code below

iMaxCount = WorksheetFunction.CountIf(Range(rRange), "=" & Max1) 'Helps determines if all players have played each other "max" times
End With

Any guidance would be appreciated.
Thanks
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi,
To gain flexibility, see two identical definitions :
VBA Code:
Set rng = Range("E6:K12")
Set rng = Range(Cells(6, 5), Cells(12, 11))
In the second instruction, you can, obviously, have 4 separate variables : rw1, cl1 and rw2, cl2

Hope this will help
 
Upvote 0
Solution
Yes... this helped... I appreciate the time you took to review my problem and respond. Thank You.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

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