Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
JD Ami
 
Posts: n/a
Default How to select a range whose name is entered in a cell.

I have four ranges named A, B, C, D.
I need to be able to copy (and paste) one of them when its name is
entered in a cell.
What is the macro syntax to get the value in a cell and use it to select
a range, please?
I would attach this macro to a button (which I know how to do) to allow
the user to enter the range name and click the button to copy it to a
fixed location (that I know how to specify)
Thanks!.


  #2   Report Post  
Bernard Liengme
 
Posts: n/a
Default

This will give you a start
Sub try()
test =Ucase( Range("E1"))
Select Case test
Case "A"
Range("A").Select
Case "B"
Range("B").Select
Case "C"
Range("C_").Select
End Select
Selection.Copy
Range("E5").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("E1").Select
End Sub


Note you cannot have a range called C it must be C_ (likewise R_)
The entry in E1 must be committed (with ENTER key or green checkmark in
Formula Bar) before running macro
--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

"JD Ami" wrote in message
...
I have four ranges named A, B, C, D.
I need to be able to copy (and paste) one of them when its name is
entered in a cell.
What is the macro syntax to get the value in a cell and use it to select
a range, please?
I would attach this macro to a button (which I know how to do) to allow
the user to enter the range name and click the button to copy it to a
fixed location (that I know how to specify)
Thanks!.




  #3   Report Post  
JD Ami
 
Posts: n/a
Default

Thanks, Bernard!

Works if all ranges below are on same sheet, but in my app A, B,....D are all
in a table on another sheet.

Also, prior to asking for help, I tried another approach... but could not get
the syntax required to make it work.

' Dim cycle As String
' cycle = Evaluate(Range("c_cycle")).Value
' Range("cycle").Select
' Selection.Copy
' Range("c_input_top").Select
' ActiveSheet.Paste
' Application.CutCopyMode = False


Bernard Liengme wrote:

This will give you a start
Sub try()
test =Ucase( Range("E1"))
Select Case test
Case "A"
Range("A").Select
Case "B"
Range("B").Select
Case "C"
Range("C_").Select
End Select
Selection.Copy
Range("E5").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("E1").Select
End Sub

Note you cannot have a range called C it must be C_ (likewise R_)
The entry in E1 must be committed (with ENTER key or green checkmark in
Formula Bar) before running macro
--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

"JD Ami" wrote in message
...
I have four ranges named A, B, C, D.
I need to be able to copy (and paste) one of them when its name is
entered in a cell.
What is the macro syntax to get the value in a cell and use it to select
a range, please?
I would attach this macro to a button (which I know how to do) to allow
the user to enter the range name and click the button to copy it to a
fixed location (that I know how to specify)
Thanks!.



  #4   Report Post  
JD Ami
 
Posts: n/a
Default

Please disregard... I was able to work around this by starting at the input
sheet, then selecting the sheet where A, B...D are located, continuing your code,
then jumping back to the input sheet.

Thanks, again, Bernard!

cycle = UCase(Range("c_cycle"))
Sheets("tables").Select
Select Case cycle
Case "A"
Range("A").Select
Case "B"
Range("B").Select
Case "C"
Range("C_").Select
Case "D"
Range("D").Select
End Select
Selection.Copy
Sheets("input").Select
Range("c_input_top").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("c_cycle").Select
End Sub


JD Ami wrote:

Thanks, Bernard!

Works if all ranges below are on same sheet, but in my app A, B,....D are all
in a table on another sheet.

Also, prior to asking for help, I tried another approach... but could not get
the syntax required to make it work.

' Dim cycle As String
' cycle = Evaluate(Range("c_cycle")).Value
' Range("cycle").Select
' Selection.Copy
' Range("c_input_top").Select
' ActiveSheet.Paste
' Application.CutCopyMode = False

Bernard Liengme wrote:

This will give you a start
Sub try()
test =Ucase( Range("E1"))
Select Case test
Case "A"
Range("A").Select
Case "B"
Range("B").Select
Case "C"
Range("C_").Select
End Select
Selection.Copy
Range("E5").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("E1").Select
End Sub

Note you cannot have a range called C it must be C_ (likewise R_)
The entry in E1 must be committed (with ENTER key or green checkmark in
Formula Bar) before running macro
--
Bernard V Liengme
www.stfx.ca/people/bliengme
remove caps from email

"JD Ami" wrote in message
...
I have four ranges named A, B, C, D.
I need to be able to copy (and paste) one of them when its name is
entered in a cell.
What is the macro syntax to get the value in a cell and use it to select
a range, please?
I would attach this macro to a button (which I know how to do) to allow
the user to enter the range name and click the button to copy it to a
fixed location (that I know how to specify)
Thanks!.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting data on protected worksheet Sue Excel Discussion (Misc queries) 20 November 7th 06 07:31 PM
How to Select a relative range with Using "Find" and Offset() Dennis Excel Discussion (Misc queries) 7 July 27th 05 03:57 PM
I cannot select a range Kassie Excel Discussion (Misc queries) 3 February 21st 05 06:09 AM
Select a range Kevin Excel Discussion (Misc queries) 3 February 18th 05 11:04 PM
Dynamic Formulas with Dynamic Ranges Ralph Howarth Excel Worksheet Functions 5 January 21st 05 08:44 AM


All times are GMT +1. The time now is 07:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"