• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

OnKey/SendKeys to insert new row and stop the whole new row being selected

VBXL

Member
Hello there, I've been trying to figure out a way to quickly insert new rows without lots of button presses.

If I run this through the MACRO screen, it works perfectly fine:

Code:
Public Sub NewRow()
Application.SendKeys "+( )%(ir){UP}{DOWN}"
End Sub

If I try to do it through a key binding, it doesn't.

So, I tried to break it down into stages and whilst stage one works (press shift and spacebar, then alt, i & r).

Code:
Private Sub Worksheet_Activate()
Application.OnKey "^ ", "Sheet1.NewRow"
End Sub

Public Sub NewRow()
Application.SendKeys "+( )"
Application.Wait (Now + TimeValue("0:00:01"))
Application.SendKeys "%(ir){UP}{DOWN}"
End Sub

Private Sub Worksheet_Deactivate()
Application.OnKey "^ "
End Sub

Sub Fill()
    Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
        Trend:=True
End Sub

The issue is that unlike when it's run manually, doing it this way, it sees i and r as button presses without alt. So, I am not sure how to fix this?

This
 
Why would you use Sendkeys for this? It's incredibly unreliable and should only be used as a last resort. Why not just Selection.Entirerow.Insert
 
Back
Top