HUNTING101
New Member
- Joined
- Jan 7, 2007
- Messages
- 3
I am new to VBA and trying to teach myself so please be kind.
I have a userform and i am trying to set the data in the from as CurrentRow for a next, previous or update button.
Here is a sample of what i have so far under the "Update" button but it is adding a new row to the top of my table and not updating the current data.
any help is appreciated.
Private Sub CommandButton4_Click()
Dim CurrentRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Daily Data")
If Me.TB_Date.Value = "" Then
MsgBox "Date Can Not be Blank!!!", vbExclamation, "Date"
Exit Sub
End If
Sheets("Daily Data").Select
CurrentRow = CurrentRow + 2
Rows(CurrentRow).Select
answer = MsgBox("Do you want to update this record?", vbYesNo + vbQuestion, "Update Record?")
If answer = vbYes Then
ws.Cells(CurrentRow, 1).Value = Me.TB_Date.Value
ws.Cells(CurrentRow, 2).Value = Me.CB_Contractor1.Value
ws.Cells(CurrentRow, 3).Value = Me.CB_Contractor2.Value
ws.Cells(CurrentRow, 4).Value = Me.CB_Contractor3.Value
ws.Cells(CurrentRow, 5).Value = Me.CB_Contractor4.Value
ws.Cells(CurrentRow, 6).Value = Me.CB_Contractor5.Value
I have a userform and i am trying to set the data in the from as CurrentRow for a next, previous or update button.
Here is a sample of what i have so far under the "Update" button but it is adding a new row to the top of my table and not updating the current data.
any help is appreciated.
Private Sub CommandButton4_Click()
Dim CurrentRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Daily Data")
If Me.TB_Date.Value = "" Then
MsgBox "Date Can Not be Blank!!!", vbExclamation, "Date"
Exit Sub
End If
Sheets("Daily Data").Select
CurrentRow = CurrentRow + 2
Rows(CurrentRow).Select
answer = MsgBox("Do you want to update this record?", vbYesNo + vbQuestion, "Update Record?")
If answer = vbYes Then
ws.Cells(CurrentRow, 1).Value = Me.TB_Date.Value
ws.Cells(CurrentRow, 2).Value = Me.CB_Contractor1.Value
ws.Cells(CurrentRow, 3).Value = Me.CB_Contractor2.Value
ws.Cells(CurrentRow, 4).Value = Me.CB_Contractor3.Value
ws.Cells(CurrentRow, 5).Value = Me.CB_Contractor4.Value
ws.Cells(CurrentRow, 6).Value = Me.CB_Contractor5.Value