Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Runnig a macro relative from a form control

My problem is how to link a form button to a cell and get that information
into a macro.

I have written a small practice macro to perform some matrix multiplication
assuming I have pre-selected the answer cells. Next I managed to get the
macro to automatically use the cells below the current active cell for the
answer array. Now, what I really want to do is apply this macro by selecting
a button above each array. The button has now information on where it is in
the sheet. I would like to lock it in a cell, and be able to reference the 4
cell below it as a range in my macro.

Any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Runnig a macro relative from a form control

Assuming forms buttons


Dim rng As Range

Select Case Application.Caller

Case "Button 1": Set rng = Range("C5:C8")

Case "Button 2": Set rng = Range("D5:D8")

Case "Button 3": Set rng = Range("E5:E8")

Case "Button 4": Set rng = Range("F5:F8")
End Select

'then work on rng

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Paul Jolley" wrote in message
...
My problem is how to link a form button to a cell and get that information
into a macro.

I have written a small practice macro to perform some matrix
multiplication
assuming I have pre-selected the answer cells. Next I managed to get the
macro to automatically use the cells below the current active cell for the
answer array. Now, what I really want to do is apply this macro by
selecting
a button above each array. The button has now information on where it is
in
the sheet. I would like to lock it in a cell, and be able to reference the
4
cell below it as a range in my macro.

Any ideas?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Runnig a macro relative from a form control

Here are additional approaches:

if the button is from the control toolbox toolbar

set rng = activesheet.OleObjects("Commandbutton1").BottomRig htCell
rng.offset(1,0).Resize(4,1)

Demo'd from the immediate window with a commandbutton with the lower right
corner in cell F8
set rng = activesheet.OleObjects("Commandbutton1").Bottomrig htCell
? rng.offset(1,0).Resize(4,1).Address
$F$9:$F$12

For a button from the forms toolbar
set rng1 = Activesheet.Buttons("Button 2").BottomRightCell
rng1.Offset(1,0).Resize(4,1)

Demo'd from the immediate window
For a button from the forms toolbar located with the lower right corner in G8
set rng1 = activesheet.buttons("Button 2").BottomRightCell
? rng1.offset(1,0).Resize(4,1).Address
$G$9:$G$12

You can also look at the TopLeftCell property of each.

It sounded like you are just using these as reference points, but if you
attach macros to the forms buttons, you can use a single macro and get the
button name of the button that called it with Application.Caller

Dim btn as Button
set btn = Activesheet.Buttons(Application.Caller)
msgbox btn.BottomRightCell.Address

--
Regards,
Tom Ogilvy

"Paul Jolley" wrote:

My problem is how to link a form button to a cell and get that information
into a macro.

I have written a small practice macro to perform some matrix multiplication
assuming I have pre-selected the answer cells. Next I managed to get the
macro to automatically use the cells below the current active cell for the
answer array. Now, what I really want to do is apply this macro by selecting
a button above each array. The button has now information on where it is in
the sheet. I would like to lock it in a cell, and be able to reference the 4
cell below it as a range in my macro.

Any ideas?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Runnig a macro relative from a form control

You are right in that I am trying to use the button as a reference. I
implemented the routine you suggested bellow and do indeed get the message
box with $N$6.

I'm having problems using this value. I need to either set a range to this
value plus 4 cells below OR move the active cell there and I can carry on as
normal.

I tried both, but keep getting errors. It's probably because I don't know
how to use the info given by btn.BottomRightCell.Address

I tried the following:

Dim btn As Button
Set btn = ActiveSheet.Buttons(Application.Caller)
MsgBox btn.BottomRightCell.Address

Range(btn.BottomRightCell.Offset(1, 0).Resize(4, 1)).Select

Selection.FormulaArray = "=MMULT(translation_matrix,R[-6]C:R[-3]C)"

with problems in the range command. Any ideas?

thanks for the help to date.

"Tom Ogilvy" wrote:

Here are additional approaches:

if the button is from the control toolbox toolbar

set rng = activesheet.OleObjects("Commandbutton1").BottomRig htCell
rng.offset(1,0).Resize(4,1)

Demo'd from the immediate window with a commandbutton with the lower right
corner in cell F8
set rng = activesheet.OleObjects("Commandbutton1").Bottomrig htCell
? rng.offset(1,0).Resize(4,1).Address
$F$9:$F$12

For a button from the forms toolbar
set rng1 = Activesheet.Buttons("Button 2").BottomRightCell
rng1.Offset(1,0).Resize(4,1)

Demo'd from the immediate window
For a button from the forms toolbar located with the lower right corner in G8
set rng1 = activesheet.buttons("Button 2").BottomRightCell
? rng1.offset(1,0).Resize(4,1).Address
$G$9:$G$12

You can also look at the TopLeftCell property of each.

It sounded like you are just using these as reference points, but if you
attach macros to the forms buttons, you can use a single macro and get the
button name of the button that called it with Application.Caller

Dim btn as Button
set btn = Activesheet.Buttons(Application.Caller)
msgbox btn.BottomRightCell.Address

--
Regards,
Tom Ogilvy


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Runnig a macro relative from a form control

Sub Btn_click()
Dim btn As Button
Set btn = ActiveSheet.Buttons(Application.Caller)
MsgBox btn.BottomRightCell.Address
btn.BottomRightCell.Offset(1, 0).Resize(4, 1) _
.FormulaArray = "=MMULT(translation_matrix,R[-6]C:R[-3]C)"
End Sub

worked for me.

--
regards,
Tom Ogilvy


"Paul Jolley" wrote:

You are right in that I am trying to use the button as a reference. I
implemented the routine you suggested bellow and do indeed get the message
box with $N$6.

I'm having problems using this value. I need to either set a range to this
value plus 4 cells below OR move the active cell there and I can carry on as
normal.

I tried both, but keep getting errors. It's probably because I don't know
how to use the info given by btn.BottomRightCell.Address

I tried the following:

Dim btn As Button
Set btn = ActiveSheet.Buttons(Application.Caller)
MsgBox btn.BottomRightCell.Address

Range(btn.BottomRightCell.Offset(1, 0).Resize(4, 1)).Select

Selection.FormulaArray = "=MMULT(translation_matrix,R[-6]C:R[-3]C)"

with problems in the range command. Any ideas?

thanks for the help to date.

"Tom Ogilvy" wrote:

Here are additional approaches:

if the button is from the control toolbox toolbar

set rng = activesheet.OleObjects("Commandbutton1").BottomRig htCell
rng.offset(1,0).Resize(4,1)

Demo'd from the immediate window with a commandbutton with the lower right
corner in cell F8
set rng = activesheet.OleObjects("Commandbutton1").Bottomrig htCell
? rng.offset(1,0).Resize(4,1).Address
$F$9:$F$12

For a button from the forms toolbar
set rng1 = Activesheet.Buttons("Button 2").BottomRightCell
rng1.Offset(1,0).Resize(4,1)

Demo'd from the immediate window
For a button from the forms toolbar located with the lower right corner in G8
set rng1 = activesheet.buttons("Button 2").BottomRightCell
? rng1.offset(1,0).Resize(4,1).Address
$G$9:$G$12

You can also look at the TopLeftCell property of each.

It sounded like you are just using these as reference points, but if you
attach macros to the forms buttons, you can use a single macro and get the
button name of the button that called it with Application.Caller

Dim btn as Button
set btn = Activesheet.Buttons(Application.Caller)
msgbox btn.BottomRightCell.Address

--
Regards,
Tom Ogilvy




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Runnig a macro relative from a form control

thanks for the help Tom, works a treat! Now just need to tidy things up.


"Tom Ogilvy" wrote:

Sub Btn_click()
Dim btn As Button
Set btn = ActiveSheet.Buttons(Application.Caller)
MsgBox btn.BottomRightCell.Address
btn.BottomRightCell.Offset(1, 0).Resize(4, 1) _
.FormulaArray = "=MMULT(translation_matrix,R[-6]C:R[-3]C)"
End Sub

worked for me.

--
regards,
Tom Ogilvy


"Paul Jolley" wrote:

You are right in that I am trying to use the button as a reference. I
implemented the routine you suggested bellow and do indeed get the message
box with $N$6.

I'm having problems using this value. I need to either set a range to this
value plus 4 cells below OR move the active cell there and I can carry on as
normal.

I tried both, but keep getting errors. It's probably because I don't know
how to use the info given by btn.BottomRightCell.Address

I tried the following:

Dim btn As Button
Set btn = ActiveSheet.Buttons(Application.Caller)
MsgBox btn.BottomRightCell.Address

Range(btn.BottomRightCell.Offset(1, 0).Resize(4, 1)).Select

Selection.FormulaArray = "=MMULT(translation_matrix,R[-6]C:R[-3]C)"

with problems in the range command. Any ideas?

thanks for the help to date.

"Tom Ogilvy" wrote:

Here are additional approaches:

if the button is from the control toolbox toolbar

set rng = activesheet.OleObjects("Commandbutton1").BottomRig htCell
rng.offset(1,0).Resize(4,1)

Demo'd from the immediate window with a commandbutton with the lower right
corner in cell F8
set rng = activesheet.OleObjects("Commandbutton1").Bottomrig htCell
? rng.offset(1,0).Resize(4,1).Address
$F$9:$F$12

For a button from the forms toolbar
set rng1 = Activesheet.Buttons("Button 2").BottomRightCell
rng1.Offset(1,0).Resize(4,1)

Demo'd from the immediate window
For a button from the forms toolbar located with the lower right corner in G8
set rng1 = activesheet.buttons("Button 2").BottomRightCell
? rng1.offset(1,0).Resize(4,1).Address
$G$9:$G$12

You can also look at the TopLeftCell property of each.

It sounded like you are just using these as reference points, but if you
attach macros to the forms buttons, you can use a single macro and get the
button name of the button that called it with Application.Caller

Dim btn as Button
set btn = Activesheet.Buttons(Application.Caller)
msgbox btn.BottomRightCell.Address

--
Regards,
Tom Ogilvy


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
2007 Form Control/ActiveX Control font difference Nikko963 Excel Discussion (Misc queries) 0 April 15th 09 04:21 PM
terminate a runnig macro JH Excel Programming 6 February 12th 05 05:39 AM
Possible to assign macro defined as private to a form control. Bing Excel Programming 1 December 24th 04 06:08 AM
help: master control macro and user form jasonsweeney[_20_] Excel Programming 1 January 26th 04 11:10 AM
Runnig a macro when excel opens vman Excel Programming 3 December 18th 03 06:41 PM


All times are GMT +1. The time now is 02:12 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"