Dynamic Range Selection

P

Phil P

I have a spreadsheet that goes to say column “S†and several thousand rows.
I would like the program to request a user to highlight a Range for example
A50:A55 (this is a variable range however the selections would always be in
column A. Based on the user selected range the range would be named and
program would execute code for the adjacent cells in the selected range.

Can you please assist with this code?
 
D

Dave Peterson

Dim myRng as range
dim myCell as range

set myrng = nothing
on error resume next
set myrng _
= application.inputbox(prompt:="select a single range",type:=8).areas(1)
on error goto 0

if myrng is nothing then
msgbox "ok. Quitting"
exit sub
end if

set myrng = myrng.entirerow.columns(1)

for each mycell in myrng.cells
msgbox mycell.address & vblf & mycell.offset(0,3).address
next mycell

=====
there really isn't a reason to give the range a name to work with it.
 
P

Phil P

Thanks so much for your help Dave. I will put your code in program and work
with it. Sorry for the duplicate message. I received a message failed
notification when I originally posted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top