2

I am trying to programmatic press the enter key once a value has been set to specific cell:

Private Sub TextBox1_Change()
    If TextBox1.Text = "ALC Test" Then
        Range("$F$2").Value = "17"
        ActiveWorkbook.RefreshAll
    End If
    If TextBox1.Text = "ALC Prod" Then
        Range("$F$2").Value = "54"
        ActiveWorkbook.RefreshAll
    End If
    If TextBox1.Text = "" Then
        Range("$F$2").Value = ""
        ActiveWorkbook.RefreshAll
    End If
End Sub

So that I can trigger in excel the refresh of my table But that does not to seam to work correctly

enter image description here

3
  • Your question is actually not pressing the enter key, but you want excel to recalculate (refresh) your table after a value is updated using vba. Is that correct? Commented Jan 18, 2017 at 13:34
  • @davejal Yes that is Commented Jan 18, 2017 at 13:35
  • try ActiveWorkbook.RefreshAll as I edited in my answer Commented Jan 18, 2017 at 13:38

2 Answers 2

2

Using sendkeys is correct.


If you just want to recalculate (refresh) your table data, you could do the following:

Private Sub TextBox1_Change()

If TextBox1.Text = "ALC Test" Then
        Range("$F$2").Value = "17"
        Range("$F$2").Select
        Application.SendKeys("~")

In your situation, you need to select the cell (that holds the parameters) before the enter command is send to excel.

Sign up to request clarification or add additional context in comments.

9 Comments

Thanks allot for your answer yes I did that but somehow the excel refresh is not getting triggered to update my tabel
I edited my answer, depending on what you actually want to achieve there are more options
I am sorry if that was not clear from original question: I type in my text box for example "ALC Test" then in the cell F2 the number 17 appears. The cell F2 has been set as a parameter field on witch my table is updating the part of updating the field is not working , i think that is not getting triggered since there is no enter input when I do it like that manually it works fine
Thanks for you effort ! but I am sorry still nothing happens .. update my question code
could your provide some more details? How is the table refreshed when using the enter key? Using a filter or macro ?
|
0

What you do is: change the value, and then press "enter" , which has no effect.

Use

calculate

or

activesheet.calculate

edited to make it clear:

Private Sub TextBox1_Change()
If TextBox1.Text = "ALC Test" Then
    Range("$F$2").Value = "17"
    calculate

3 Comments

Hey thanks a lot for your answer can you give me a bit more context to where I hace to set that ? or instead of what ?
Just replace your sendkey line with one of those :)
like that Application.Calculate ("~")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.