Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to: User Form to assign a user defined range to a macro variab

I want to be able to select a range of cells with a user form (using the
RefEdit control) and then pass or assign the user defined range address to a
range varaible in a seperate VB macro. I want to be able to hold the user
defined range in a range variable so I can reference multiple times within
the/a "formatting macro".

I have figured out how to display the form and get the range address
assigned inside the VB code for the user (CommandButton1 click Sub) but I can
not figure out how to assign or pass the range value out of the user form to
the range variable in the "formatting macro". I think if I put all the
"formatting macro" code in the Sub CommandButtion1_click() it would work or
this specific application or task.

Ideally I would like the UserForm to be "generic" of sorts, that way I can
call it from inside any macro I have (current or future) that performs
formating on each cell in the range or copying/moving/tranposing etc. the
range as a whole.

I think the issue I am having is a miss match of varaible types or not
setting the correct parameters when referencing variables with repsect to
their "scope". It also could be something simple that I am just over looking
- VB is a little new to me. Any assistance or light that could be shed on
this "hair wringer" is much appreciated. Thanks in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to: User Form to assign a user defined range to a macro variab

Rather than unload the userform, hide it where you would unload it.

then in the other code you can so

sAdd = Userform1.Regedit1.Value
set rng = Activesheet.Range(sAdd)
unload userform1

---------------------
General Module:
Sub Showform()
Dim sAdd As String
Dim rng As Range

UserForm1.Show
sAdd = UserForm1.RefEdit1.Value
Set rng = ActiveSheet.Range(sAdd)
Unload UserForm1
rng.Select
End Sub

---------------------
Userform Module:
Private Sub CommandButton1_Click()
Me.Hide
End Sub

As an example (worked for me)

--
Regards,
Tom Ogilvy

"TrevTrav" wrote in message
...
I want to be able to select a range of cells with a user form (using the
RefEdit control) and then pass or assign the user defined range address to

a
range varaible in a seperate VB macro. I want to be able to hold the user
defined range in a range variable so I can reference multiple times within
the/a "formatting macro".

I have figured out how to display the form and get the range address
assigned inside the VB code for the user (CommandButton1 click Sub) but I

can
not figure out how to assign or pass the range value out of the user form

to
the range variable in the "formatting macro". I think if I put all the
"formatting macro" code in the Sub CommandButtion1_click() it would work

or
this specific application or task.

Ideally I would like the UserForm to be "generic" of sorts, that way I can
call it from inside any macro I have (current or future) that performs
formating on each cell in the range or copying/moving/tranposing etc. the
range as a whole.

I think the issue I am having is a miss match of varaible types or not
setting the correct parameters when referencing variables with repsect to
their "scope". It also could be something simple that I am just over

looking
- VB is a little new to me. Any assistance or light that could be shed on
this "hair wringer" is much appreciated. Thanks in advance.



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
Can I Assign A User Defined Function To A Cell? smartin Excel Worksheet Functions 0 June 28th 09 10:25 PM
How to assign a short cut key for user defined word? Siva Excel Discussion (Misc queries) 4 August 27th 07 01:20 PM
User Defined Functions - Help Text - Make it Easy for the User Andibevan[_2_] Excel Programming 4 March 17th 05 09:51 AM
User-defined data type; Error: Only User-defined types... tiger_PRM Excel Programming 1 July 18th 04 03:32 PM
passing a range to a user defined function using a form davek Excel Programming 1 December 24th 03 07:40 AM


All times are GMT +1. The time now is 06:18 AM.

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

About Us

"It's about Microsoft Excel"