-3

I'm new and know the basic Excel VBA, now I'm trying one of the logic, I have the user form and the data which we enter in user form that it should store in particular table, like in that Excel sheet I have the predefined table, in that for example -> D5 & E5 is the cells contain table header.

So whenever I'm entering the data first time, the data should store in D6 & E6 accordingly, likewise I want to store data next to next in under D & E column? Anyone help to complete this code!

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • 4
    Pls post the code you have so far. – Kajkrow Jul 09 '18 at 10:55
  • 7
    Welcome to SO. Please show what you have tired to do so far. – T. Nesset Jul 09 '18 at 10:55
  • Watch this video: [Excel VBA Introduction Part 5 - Selecting Cells (Range, Cells, Activecell, End, Offset)](https://www.youtube.com/watch?v=c8reU-H1PKQ&t=3123s&index=5&list=PLNIs-AWhQzckr8Dgmgb3akx_gFMnpxTN5). – TinMan Jul 09 '18 at 10:56
  • Have a look here on [how to find the last used row](https://stackoverflow.com/a/38882823/3219613). This would be a good start for you to find the next empty row in your column D or E. – Pᴇʜ Jul 09 '18 at 11:07

1 Answers1

0

With the vague information you posted, I can only assume, guess and try to answer that question, so if you have a UserForm with two textboxes and a command button, and you want to add their values into the next available row in columns D & E, when the command button is clicked, the following will do that:

Private Sub cmdSave_Click()
    Dim LastRow As Long
    Dim ws As Worksheet: Set ws = Sheets("Sheet1")
    'declare and set your worksheet, amend as required
    LastRow = ws.Cells(ws.Rows.Count, "D").End(xlUp).Row
    'get the last row with data on Column D

    ws.Range("D" & LastRow + 1).Value = txtFirstTextBox.Text
    'pass the value from first textbox to Column D
    ws.Range("E" & LastRow + 1).Value = txtSecondTextBox.Text
    'pass the value from second textbox to Column E
    txtFirstTextBox.Text = ""
    txtSecondTextBox.Text = ""
End Sub
Xabier
  • 7,587
  • 1
  • 8
  • 20