+ Reply to Thread
Results 1 to 8 of 8

On Keyboard Event

  1. #1
    Registered User
    Join Date
    01-05-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2007
    Posts
    7

    On Keyboard Event

    Hello all,

    I am trying to write a macro where-in I want to assign a number to a particular letter and whenever I type that letter, it should be replaced by the number anywhere in the workbook. For example, I want to assign b=1 and s=2. Whenever I type b in any cell it should be replaced 1 and similarly with s should be replaced by 2. How can I do it?

    Thanks in advance.

    Cheers. :-)

  2. #2
    Valued Forum Contributor Kamboj's Avatar
    Join Date
    09-25-2014
    Location
    India
    MS-Off Ver
    2003 - 2010
    Posts
    430

    Re: On Keyboard Event

    This code help you
    double click on sheet1 under code editor(Alt+F11)
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-05-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: On Keyboard Event

    Thanks a lot buddy!! It worked like a charm. So, if I want to apply this to the entire workbook how do I do it? I tried to save this code under "workbook" but it doesn't work.

  4. #4
    Valued Forum Contributor Kamboj's Avatar
    Join Date
    09-25-2014
    Location
    India
    MS-Off Ver
    2003 - 2010
    Posts
    430

    Re: On Keyboard Event

    paste this on every sheet editor

  5. #5
    Registered User
    Join Date
    01-05-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: On Keyboard Event

    Yeah, thought as much. Thanks anyway. Is it possible to have this enabled for a particular row or a range of cells in a worksheet?

  6. #6
    Valued Forum Contributor Kamboj's Avatar
    Join Date
    09-25-2014
    Location
    India
    MS-Off Ver
    2003 - 2010
    Posts
    430

    Re: On Keyboard Event

    define that range in target
    suppose you want it to row no.2
    then
    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor Kamboj's Avatar
    Join Date
    09-25-2014
    Location
    India
    MS-Off Ver
    2003 - 2010
    Posts
    430

    Re: On Keyboard Event

    AND FOR A RANGE HERE B1:B5
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-05-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: On Keyboard Event

    Thanks. I improvised on your code as below (this is what I want to achieve). It ran well the first time and started acting up when I tried it subsequent times. Same with your original code as well for the target range.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address >= "$F$2" And Target.Address <= "$F$100" Then
    Target.Select
    Selection.Replace What:="s", Replacement:="2", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False
    End If
    If Target.Address >= "$F$2" And Target.Address <= "$F$100" Then
    Target.Select
    Selection.Replace What:="b", Replacement:="1", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False
    End If
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Userform multipage control - exit event not firing or event order
    By jane serky in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2013, 10:23 AM
  2. Replies: 4
    Last Post: 11-07-2012, 04:02 PM
  3. Replies: 1
    Last Post: 02-08-2007, 10:57 AM
  4. keyboard event in user form
    By gpjb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-27-2005, 06:13 PM
  5. Keyboard/Mouse click event
    By bhavesh78 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-29-2005, 07:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1