Set Focus to Particular Cell

treeppm

Board Regular
Joined
Jun 3, 2015
Messages
60
Hello Friends.

If i enter data from A1-A5 when i Press enter in A5 how to set focus to B1?. Kindly let me know all possible way's
Thanks in Advance

With Regards
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
This is a auto sheet event script
Your Workbook must be Macro enabled
To install this code:

Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window




Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A5")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Range("B1").Select
End If
End Sub

After entering data in Range("A5") you will then set focus on "B1"
 
Last edited:
Upvote 0
You do not want to use Vba?
What is this not doing for you?
 
Last edited:
Upvote 0
No bro.. I asked for VBA. but my question was wrong. i should have to asked is there any other coding like that?.
Thanks for that previous answer bro. working fine. I just ask for my knowledge

Thanks with Regards
 
Last edited:
Upvote 0
Glad I was able to help you. Come back here to Mr. Excel next time you need additional assistance.
No bro.. I asked for VBA. but my question was wrong. i should have to asked is there any other coding like that?.
Thanks for that previous answer bro. working fine. I just ask for my knowledge

Thanks with Regards
 
Upvote 0
There are several ways to do nearly everything in Excel.
I could have provided it this way with Offset command:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A5")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Target.Offset(-4, 1).Select
End If
End Sub

Set Focus is used sometimes when doing code in UserForms.

For example:

Code:
TextBox1.SetFocus

Or it could be written this way with GOTO command

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A5")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Application.Goto Range("B1")
End If
End Sub
 
Last edited:
Upvote 0
Excellent bro.. Nice explanations. I got exactly how it's work. Also i need another help. after i entered value in "C7" how to sort order(descending) value from the cells B1-B5

Thanks with Regards
 
Last edited:
Upvote 0
Try this:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Version 2
If Not Intersect(Target, Range("A5")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Range("B1").Select
End If
If Not Intersect(Target, Range("C7")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Range("B1:B5").Sort Key1:=Range("B1"), Order1:=xlDescending, Header:=xlNo
End If
End Sub
 
Upvote 0
PS:

You should be aware. A worksheet change event requires a manual change to a sheet. A change to the sheet due to a formula change will not activate the script.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top