473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

EXCEL -vb - Spin Button - Focus

Excel 2000 (9.0.2720) vb-6.
We have a column of Cells and the SpinButton. Let say for this example:
column 1 row 1 cell have value "A"
column 1 row 2 cell have value "B"
column 1 row 3 cell have value "C"
Cell with value "A" is is highlited (has focus)
Now we press "SpinButton" down. We exchange values "A" and "B"
so we have B - row 1
A - row 2
C - no change
We want A in row 2 be in focus, so we activate Cells(1,2)in last statement of spin down subroutine.
Well - the cell is activated for a split of second and then SpinButton get a focus - taking focus off our cell !!!. Now
SpinButton is like two CommandButton but CommandButton have a property: TakeFocusOnClick - TRUE or FALSE but SpinButton don't.(In my opinion MS missed this - hmmmmm?)
So, SpinButton is geting focus after "spin down" event is already finished. Now Cell in row 2 (value A)is active but SpinButton has a focus. If we press "down" again it works good bcse SpinButton (having focus now) is not trying to get focus again. How to solve this ???.
Sep 23 '11 #1

✓ answered by Mihail

A solution can be:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Sub SpinButton1_GotFocus()
  4.     ActiveCell.Activate
  5. End Sub
  6.  
  7. Private Sub SpinButton1_SpinDown()
  8. Dim R As Integer
  9.     R = ActiveCell.Row + 1
  10.     If R > 65535 Then R = R - 1 'last row in sheet
  11.     Cells(R, 1).Activate
  12. End Sub
  13.  
  14. Private Sub SpinButton1_SpinUp()
  15. Dim R As Integer
  16.     R = ActiveCell.Row - 1
  17.     If R < 1 Then R = R + 1 'Firs row in sheet
  18.     Cells(R, 1).Activate
  19. End Sub
Si, kapish :))

7 5091
Mihail
759 512MB
What you wish to solve?
Sep 24 '11 #2
Well, Mihail
I'm loosing a focus from a cell that should have it - every second time when I press SpinButton. Would be solution - set Focus on SpinButton before pressing it, as I explained before when SpinButton has a focus it don't try get it back, so my cell properly maintain her focus for now, but next clic and SB takes focus again - Kapish ?
Sep 26 '11 #3
Sorry, I'm wrong - It is not a solution to set focus on SB, you have to press it first then program knows that it was pressed, besides there is no instruction to set focus or activate SB ??!!
Sep 26 '11 #4
Mihail
759 512MB
A solution can be:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Sub SpinButton1_GotFocus()
  4.     ActiveCell.Activate
  5. End Sub
  6.  
  7. Private Sub SpinButton1_SpinDown()
  8. Dim R As Integer
  9.     R = ActiveCell.Row + 1
  10.     If R > 65535 Then R = R - 1 'last row in sheet
  11.     Cells(R, 1).Activate
  12. End Sub
  13.  
  14. Private Sub SpinButton1_SpinUp()
  15. Dim R As Integer
  16.     R = ActiveCell.Row - 1
  17.     If R < 1 Then R = R + 1 'Firs row in sheet
  18.     Cells(R, 1).Activate
  19. End Sub
Si, kapish :))
Sep 26 '11 #5
NeoPa
32,556 Expert Mod 16PB
I handle this irritation by selecting the worksheet that the cell is on. I've sometimes found that not to work though. Try selecting the current selection instead :
Expand|Select|Wrap|Line Numbers
  1. Call Selection.Select
Sep 26 '11 #6
Micha,
I totaly overlooked "Object_GotFocus()". Of course your solution is perfect. Si,Si Kapish now.!
Many thanks
Janusz
Sep 27 '11 #7
NeoPa - Thanks - I used Mihail solution.
Cheers
Sep 27 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ronny Sigo | last post by:
Hello all, I have to open a readonly Excel sheet from clicking on a button on an access form. So far no problem: Dim ObjXL As Excel.Application Dim ObjXLBook As Excel.Workbook Dim ObjXLSheet As...
5
by: Mike | last post by:
Can I trigger a button press event without putting focus on the button? I am making a form full of buttons that can be used as a keyboard on a touchscreen. If I have a textbox which has focus...
0
by: JoRo | last post by:
I am working on a project where I want a very user-friendly interface. I have a datagrid of categories that uses the EditCommandColumn to do in-line editing of the category name. On the page is...
3
by: Philip Townsend | last post by:
I have an aspx page that contains 2 user controls, each containing a seperate textbox and button. I would like to specify that one of the buttons recieve focus when the page loads. Also, I would...
0
by: devour | last post by:
i am using glade+pygtk+python ,what i wanna do is get a float type number from user, make some mathematical operations using python then output the result using glade. i tried text entry but i...
3
pentahari
by: pentahari | last post by:
In VB6, I have created the form look like the message box. but one problem has occurred that the one button had already focused but the rectangle focus symbol appeared on the focused button. But the...
3
by: JFKJr | last post by:
Hello everyone, the following is the code which opens an excel file and creates a toolbar button. And, when I click the toolbar button as shown at line #28, the code should call the "Example"...
1
MitchR
by: MitchR | last post by:
Good Morning Folks; I have a question that is pretty far fetched but here goes nothing... I am looking to find a way to insert a macro into an Excel command button located in an Access VBA...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.