1024programmer Java Is there any GotFocus event for ExcelCell?

Is there any GotFocus event for ExcelCell?

Whenever I focus on a specific cell, and if that cell contains a value less than 2, then the content in that cell should be multiplied by 60.

By the way, I can focus to a specific cell by using the navigation keys or clicking on a partiuclar cell or anything.

For example, I focus on a specific cell with a value of 1.5. Then, my VBA program should automatically convert that cell value to 90 in the format of 60*1.5 = 90.

I know very little about programming in Excel. I cannot open most websites due to company security policies.

Can anyone help me!

1> Gary’s Stude..:


Assume the cell in question is CellB9. Place the following event macro in the worksheet code area:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
     Dim B9 As Range
     Set B9 = Range("B9")
     If Intersect(Target, B9) Is Nothing Then
     Else
         If B9 <2 Then B9 = 60 * B9
     End If
 End Sub
 

Because it is worksheet code, it is easy to install and use automatically:

    Right-click on the tab name near the bottom of the Excel window

    Select View Code – this will open a VBE window

    Paste the content and close the VBE window

If you have any concerns, try it on the trial worksheet first.

If you save the workbook, the macros will be saved with it. If you are using a version of Excel after 2003, you must save the file as .xlsm instead of .xlsx

To delete a macro:

    Calling up the VBE window as described above

    Clear code

    Close VBE window

To learn more about macros, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

To learn more about event macros (sheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm

Macros must be enabled for this to work properly!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/770317

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索