My current code used to insert new data from userform. There's sometimes the data already exist in the current listing. There's another code that will decide to select new empty row or select existing row (with data) then defined the CurrentRow value. When this happen, I want my code be able to check if the textbox contain data (not empty) or not then update this data into existing row that already contained data. Existing data will be replace by new data from textbox. Skip those empty textbox.
So,
If activecell value is not empty and textbox not empty > replace with new data from textbox
If activecell value is empty insert whatever data from textbox into new row.
Private Sub OKButton_Click()
Dim CurrentRow As Long
Dim ctl As Control
Dim ChkBox As String
'Check for CheckBox value
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" And ctl = True Then
ChkBox = ctl.Caption & " " & ChkBox
End If
Next ctl
''create new entry
CurrentRow = ActiveCell.Row
Cells(CurrentRow, 2).Value = TitleTextBox.Value
Cells(CurrentRow, 3).Value = AuthorTextBox.Value
Cells(CurrentRow, 4).Value = CopyTextBox.Value
Cells(CurrentRow, 5).Value = ISBNTextBox.Value
Cells(CurrentRow, 6).Value = CallNoTextBox.Value
Cells(CurrentRow, 7).Value = PublicationTextBox.Value
Cells(CurrentRow, 8).Value = ChkBox
Call UserForm_Initialize
End Sub
UPDATE: Code below decide which row to select.
Sub DupCheck(txt, ColNo As Long, theLabel As Object)
Dim m
With Worksheets("Booklist")
m = Application.Match(txt, .Columns(ColNo), 0)
If Not IsError(m) Then
theLabel.Caption = "Duplicate" & " " & .Cells(m, ColNo).Address
.Activate
.Rows(m).Select
Else
theLabel.Caption = ChrW(&H2713)
.Activate
.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Select
End If
End With
End Sub