PC Review


Reply
Thread Tools Rate Thread

Button Visibility / Selectionchange Problem

 
 
mastermind
Guest
Posts: n/a
 
      11th Jan 2007
I have a range containing vlookup formuals (AX17:AX31). The index
number for these functions are contained in a separate range
(BK17:BK31), and are each manipulated by a seperate spinner button. I
am curious if there is a way to make it so that when a particular cell
is selected only the button affecting the formula is visible. Is this
even possible? If anyone can think of a better way to do this let me
know. I don't know if there is a way to make a floating button that
aligns itself/adjusts the formula of the selected cell. Any ideas or
solutions will be greatly appreciated. Thank You.

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      11th Jan 2007
I put a spinner from the Forms control toolbox on the worksheet.

I called it "Spinner 1".

Then I used this code behind the worksheet:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim mySpinner As Shape
Dim myVal As Long
Dim LinkedCellColumn As String

LinkedCellColumn = "BX"

Set mySpinner = Nothing
On Error Resume Next
Set mySpinner = Me.Shapes("Spinner 1")
On Error GoTo 0

If mySpinner Is Nothing Then
MsgBox "Design error--no spinner"
Exit Sub
End If

If Target.Cells.Count > 1 Then
mySpinner.Visible = False
Exit Sub
End If

If Intersect(Me.Range("17:31"), Target) Is Nothing Then
mySpinner.Visible = False
Exit Sub
End If

mySpinner.Visible = True
With Target
mySpinner.Top = .Top
mySpinner.Left = .Offset(0, 1).Left
myVal = Me.Cells(Target.Row, LinkedCellColumn).Value
mySpinner.OLEFormat.Object.LinkedCell _
= Me.Cells(Target.Row, LinkedCellColumn).Address(external:=True)
Me.Cells(Target.Row, LinkedCellColumn).Value = myVal
End With

End Sub

When I select a cell in rows 17:31, the spinner pops up to the cell to the right
in the same row--don't select IV or add some code to stop that error!





mastermind wrote:
>
> I have a range containing vlookup formuals (AX17:AX31). The index
> number for these functions are contained in a separate range
> (BK17:BK31), and are each manipulated by a seperate spinner button. I
> am curious if there is a way to make it so that when a particular cell
> is selected only the button affecting the formula is visible. Is this
> even possible? If anyone can think of a better way to do this let me
> know. I don't know if there is a way to make a floating button that
> aligns itself/adjusts the formula of the selected cell. Any ideas or
> solutions will be greatly appreciated. Thank You.


--

Dave Peterson
 
Reply With Quote
 
mastermind
Guest
Posts: n/a
 
      11th Jan 2007
Hey, thanks a lot. The code works great. However, I need a little bit
of help in modifying it now. The cells containing the Vlookup formulas
are merged cells (AX17:BG17....all the way down to the last row
AX31:BG31), and while the code works great on a single cell it will not
run when the cells are merged. Is there a way to make it respond to
the merged cells? Thank you


Dave Peterson wrote:
> I put a spinner from the Forms control toolbox on the worksheet.
>
> I called it "Spinner 1".
>
> Then I used this code behind the worksheet:
>
> Option Explicit
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
>
> Dim mySpinner As Shape
> Dim myVal As Long
> Dim LinkedCellColumn As String
>
> LinkedCellColumn = "BX"
>
> Set mySpinner = Nothing
> On Error Resume Next
> Set mySpinner = Me.Shapes("Spinner 1")
> On Error GoTo 0
>
> If mySpinner Is Nothing Then
> MsgBox "Design error--no spinner"
> Exit Sub
> End If
>
> If Target.Cells.Count > 1 Then
> mySpinner.Visible = False
> Exit Sub
> End If
>
> If Intersect(Me.Range("17:31"), Target) Is Nothing Then
> mySpinner.Visible = False
> Exit Sub
> End If
>
> mySpinner.Visible = True
> With Target
> mySpinner.Top = .Top
> mySpinner.Left = .Offset(0, 1).Left
> myVal = Me.Cells(Target.Row, LinkedCellColumn).Value
> mySpinner.OLEFormat.Object.LinkedCell _
> = Me.Cells(Target.Row, LinkedCellColumn).Address(external:=True)
> Me.Cells(Target.Row, LinkedCellColumn).Value = myVal
> End With
>
> End Sub
>
> When I select a cell in rows 17:31, the spinner pops up to the cell to the right
> in the same row--don't select IV or add some code to stop that error!


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      11th Jan 2007
You mean it fails when it tries to put the spinner in the cell to the right?

If that's the case, maybe you can put it in the cell to the left
(.offset(0,-1)).

If you mean that it's a problem when you change selection, then maybe just
dropping that check for multiple cells:

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim mySpinner As Shape
Dim myVal As Long
Dim LinkedCellColumn As String

LinkedCellColumn = "BX"

Set mySpinner = Nothing
On Error Resume Next
Set mySpinner = Me.Shapes("Spinner 1")
On Error GoTo 0

If mySpinner Is Nothing Then
MsgBox "Design error--no spinner"
Exit Sub
End If

Set Target = Target.Cells(1)

If Intersect(Me.Range("17:31"), Target) Is Nothing Then
mySpinner.Visible = False
Exit Sub
End If

mySpinner.Visible = True
With Target
mySpinner.Top = .Top
mySpinner.Left = .Offset(0, 1).Left
myVal = Me.Cells(Target.Row, LinkedCellColumn).Value
mySpinner.OLEFormat.Object.LinkedCell _
= Me.Cells(Target.Row, LinkedCellColumn).Address(external:=True)
Me.Cells(Target.Row, LinkedCellColumn).Value = myVal
End With

End Sub


(I hate merged cells!)

mastermind wrote:
>
> Hey, thanks a lot. The code works great. However, I need a little bit
> of help in modifying it now. The cells containing the Vlookup formulas
> are merged cells (AX17:BG17....all the way down to the last row
> AX31:BG31), and while the code works great on a single cell it will not
> run when the cells are merged. Is there a way to make it respond to
> the merged cells? Thank you
>
> Dave Peterson wrote:
> > I put a spinner from the Forms control toolbox on the worksheet.
> >
> > I called it "Spinner 1".
> >
> > Then I used this code behind the worksheet:
> >
> > Option Explicit
> > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> >
> > Dim mySpinner As Shape
> > Dim myVal As Long
> > Dim LinkedCellColumn As String
> >
> > LinkedCellColumn = "BX"
> >
> > Set mySpinner = Nothing
> > On Error Resume Next
> > Set mySpinner = Me.Shapes("Spinner 1")
> > On Error GoTo 0
> >
> > If mySpinner Is Nothing Then
> > MsgBox "Design error--no spinner"
> > Exit Sub
> > End If
> >
> > If Target.Cells.Count > 1 Then
> > mySpinner.Visible = False
> > Exit Sub
> > End If
> >
> > If Intersect(Me.Range("17:31"), Target) Is Nothing Then
> > mySpinner.Visible = False
> > Exit Sub
> > End If
> >
> > mySpinner.Visible = True
> > With Target
> > mySpinner.Top = .Top
> > mySpinner.Left = .Offset(0, 1).Left
> > myVal = Me.Cells(Target.Row, LinkedCellColumn).Value
> > mySpinner.OLEFormat.Object.LinkedCell _
> > = Me.Cells(Target.Row, LinkedCellColumn).Address(external:=True)
> > Me.Cells(Target.Row, LinkedCellColumn).Value = myVal
> > End With
> >
> > End Sub
> >
> > When I select a cell in rows 17:31, the spinner pops up to the cell to the right
> > in the same row--don't select IV or add some code to stop that error!


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
SelectionChange problem Brettjg Microsoft Excel Programming 5 3rd Mar 2009 01:00 PM
Button visibility =?Utf-8?B?U3BlbmNlcg==?= Microsoft Access VBA Modules 3 16th Nov 2006 02:12 AM
Command Button Visibility Problem =?Utf-8?B?SWFu?= Microsoft Excel Programming 2 20th Feb 2004 06:51 PM
selectionchange problem micher Microsoft Excel Programming 2 27th Jan 2004 07:15 PM
SelectionChange problem =?Utf-8?B?TWljaGVy?= Microsoft Excel Programming 0 23rd Jan 2004 10:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:47 PM.