Need help with data from coding....try to create an update button

M

marty6

Here's the code:

Private Sub CommandButton1_Click()

Dim lastRow As Object

Set lastRow = Sheet1.Range("a65536").End(xlUp)

lastRow.Offset(1, 0).Value = TextBox1.Text
lastRow.Offset(1, 1).Value = TextBox2.Text
lastRow.Offset(1, 2).Value = TextBox3.Text

MsgBox "One record written to Sheet1"

response = MsgBox("Do you want to enter another record?", _
vbYesNo)

If response = vbYes Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""

TextBox1.SetFocus

Else
Unload Me
End If

End Sub
Private Sub CommandButton2_Click()
End
End Sub


Private Sub btnPrevious_click()
If ActiveCell.Column <> 1 Then
Cells(ActiveCell.Row, 1).Select
End If
If ActiveCell.Row <> 1 Then
ActiveCell.Offset(-1, 0).Select
TextBox1.Text = ActiveCell.Value
TextBox2.Text = ActiveCell.Offset(1, 1).Value
TextBox3.Text = ActiveCell.Offset(1, 2).Value
End If
End Sub


Private Sub btnNext_click()
Dim lastRow As Long

If ActiveCell.Column <> 1 Then
Cells(ActiveCell.Row, 1).Select
End If
If ActiveCell.Row <> lastRow Then
ActiveCell.Offset(1, 0).Select
TextBox1.Text = ActiveCell.Value
TextBox2.Text = ActiveCell.Offset(1, 1).Value
TextBox3.Text = ActiveCell.Offset(1, 2).Value
End If
End Sub


As one can tell, it's from Microsoft's help center. As you can see,
have the previous and next buttons added. Is there a way to add a
"Update button" so that I can update the data in those cells from thi
form?

I would like to do something like this:
Private Sub btnUpdate_click()
end sub

But I don't know the code on how to. Can somebody lead me in the righ
direction on how to write the code. I have done searches on this sit
and have not really come up with anything helpful.

Any help is appreciated

marty
 
D

DSC

Hi Marty

Is this what you want


Code
-------------------

Private Sub btnUpdate_Click()
ActiveCell.Formula = TextBox1.Text
ActiveCell.Offset(1, 1).Formula = TextBox2.Text
ActiveCell.Offset(1, 2).Formula = TextBox3.Text

MsgBox "Record Updated"
End Sub

-------------------


a word of caution here you are looking at a particular cell(Activ
cell) one diagnoally down and right from it and one horizontal to th
second one in such a form as

x
x x

if this is not what you want and you want the choices to be horizonta
change your .offset(1,?) to .offset(0,?) where ? = 1 or 2

HTH

Davi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top