What is the Best/Simplest way to define RANGES

BIGTONE559

Active Member
Joined
Apr 20, 2011
Messages
336
Greetings,

I have a range that will change from month to month. My current code defines that range as D5:D30. (Just for trial purposes) In actuality the database is from D2:D9319. However i'd like the code to remain unchange from week to week. I would imagine that i would need to dim a range but i figured i seek help of more knowledgeable people.

Please help!!!! and let me know if there are enough details.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi,

Do you want to define a dynamic named-range in the worksheet? In this case, your range has numbers , text, mixed?

or

inside VBA get the range like

Code:
Dim lastRow as Long, rng as Range
 
With Sheets("Sheet1")
   lastRow = .Cells(.rows.count, "B").End(xlUp).Row
 
  Set rng = .Range("B2:B" & lastRow)
End With

M.
 
Upvote 0
Marcelo i was thinking similar to your second example. I want to define the range from vba. In your example you used B so I'm assuming i would just change that to D.

I'm going to try your example out it appears to be exactly what i'm looking for.
 
Upvote 0
Marcelo i was thinking similar to your second example. I want to define the range from vba. In your example you used B so I'm assuming i would just change that to D.

I'm going to try your example out it appears to be exactly what i'm looking for.

Hi,

Yes change B to D. I dont know why i've used B...

M.
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,317
Members
452,905
Latest member
deadwings

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