Share via

Codes for press “F2” button and then “Enter” button

Anonymous
2012-02-04T14:04:13+00:00

Hi,

 I have data in around 200 cells. I need to go to each cell and press “F2” button and then “Enter” button.

Can I have macro codes,  that should perform above task in selected cells. I could not get these code by recording.

Regards,

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. Anonymous
    2012-02-04T14:36:20+00:00

    Select the cells and run:

    Sub RefreshCells()

    Dim r As Range, rr As Range

    Set rr = Selection

    For Each r In rr

        r.Select

        Application.SendKeys "{F2}"

        Application.SendKeys "{ENTER}"

        DoEvents

    Next

    End Sub

    200+ people found this answer helpful.
    0 comments No comments

Answer accepted by question author

  1. Anonymous
    2012-02-04T18:15:09+00:00

    Vishu wrote:

    I have data in around 200 cells. I need to go to each cell and press “F2” button and then “Enter” button.  Can I have macro codes,  that should perform above task in selected cells. I could not get these code by recording.

    Of course, this is needed, for example, when you entered numbers or formulas into cells originally formatted as Text, then you change the format to General or some other numeric formula.  As we know, Excel does not automatically change the cell contents immediately.  We must "edit" each cell by pressing F2, then Enter.

    FYI, if your original data are constants, you can simply put the number 1 into some cell and copy it, select the cells to "edit", right-click and click on Paste Special, select Multiply, and press OK.  Then you can delete the number 1.

    But if you have formulas, you can use the following macro.  Select the range of cells to change first.  The formula works only for cells with constants and non-array-entered formulas.  But then, so does your procedure of pressing F2, then just Enter.

    Sub reEnter()

    For Each r In Selection

        r.Formula = r.Formula

    Next

    End Sub

    80+ people found this answer helpful.
    0 comments No comments

21 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-02-04T21:51:19+00:00

    One less step..............copy an empty cell and paste special>add

    If you have formulas...........

    Selecting and using edit>replace   =  with  =   replace all  does same job without the macro.

    Gord

    30+ people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2013-06-07T16:27:55+00:00

    it worked!!

    Selecting and using edit>replace = with = replace all does same job without the macro

    So many times doing the F2 / ENTER and the solution was so simple

    Thanks a lot for sharing :)

    8 people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2012-02-05T03:35:47+00:00

    If all cells were in the same column, simplest to use Data - Text to Columns, choose delimited, choose only tab separator, then click finish.

    If this doesn't work, you probably have trailing HTML nonbreaking spaces, in which case you'd have to delete them using Replace. Press [Ctrl]+H to display the Replace dialog, in the Find what box clear anything there then hold down an [Alt] key and press 0160 using your numeric keypad (on laptops, hold down the [Fn] key in addition to the [Alt] key and press MJOM). That should enter a single nonbreaking space. Then clear the Replace with box and click on Replace All.

    7 people found this answer helpful.
    0 comments No comments