Force “F2”+“Enter” on range of cells

后端 未结 12 1713
伪装坚强ぢ
伪装坚强ぢ 2021-01-04 05:31

I have an Excel 2010 worksheet which has macros to copy data from other sheets into a specific format on another sheet.

The data copies but I have an issue with the

相关标签:
12条回答
  • 2021-01-04 05:50

    It seems odd that you would need to send keys F2 + Enter. What is the formatting before you run the macro? Try formatting the whole column that way (it won't affect the text).

    Columns("C:C").NumberFormat = "yyyy-mm-dd"
    
    0 讨论(0)
  • 2021-01-04 05:53

    I struggled to get this to work too. My problem has been not just dates but also data with a single quote in front of it. What I hacked together works great for me. It cleans up over 70,000 cells very fast. Hope it works for you:

    (you will change the range and such to suit your needs)

        Dim MyRange As Range
    
        Set MyRange = Range(Cells(2, 7), [G1].End(xlDown))
    
        For Each MyRange In MyRange.Cells
        'Mimic F2 without SendKeys
            MyRange.Value = MyRange.Value
        Next
    
    0 讨论(0)
  • 2021-01-04 05:57

    I just set the cell to the right of the top entry equal to a formula that multiplied the problem cell times 1. That new cell was a proper number, so then double clicking the handle extended it down the whole column fixed them all!

    0 讨论(0)
  • 2021-01-04 05:57

    It is possible to use Text to Columns to solve this problem

    1) Highlight the column of data

    2) Go to Data -> Text To Columns -> Delimited -> (deselect everything) -> Next

    3) On page 3 of the wizard, set the Column Data Format YMD

    4) OK

    0 讨论(0)
  • 2021-01-04 06:04

    I use this simple macro to apply F2 + Enter on the currently selected range:

    Sub ApplyF2()
        Selection.Value = Selection.FormulaR1C1
    End Sub
    
    0 讨论(0)
  • 2021-01-04 06:06
    Sub RefreshCells()
    
    Dim r As Range, rr As Range
    Set rr = Selection
    For Each r In rr
    r.Select
    Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
       Application.CutCopyMode = False
    
        Application.SendKeys "{F2}"
        Application.SendKeys "{ENTER}"
        Application.SendKeys "+{ENTER}"
        DoEvents
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
       Application.CutCopyMode = False
    
        Application.SendKeys "{ENTER}"
    
        DoEvents
    
    Next
    
    
    
    End Sub
    
    0 讨论(0)
提交回复
热议问题