B
Brian
I am trying to delete rows based on 1. user selecting to overwrite data and
2. criteria met in both column A and column B. The code below is linked to
a button on a form with 3 possible selections and the form pops up when data
entered on another form is found to be duplicate to data already existing in
the database. I use similar code to detect "duplicate rows" in the sub that
brings up the selection form and it works.
thanks in advance.
Private Sub OKToProceed_Click()
'Check if user wants to overwrite duplicate data found then delete existing
row
'with duplicate data and go back to mill measurements form
If ExistingDataFound.Overwrite.Value = True Then
'SOMETHING WRONG...THE TEST FOR DUPLICATE ROWS DOESN'T WORK HERE
Dim rngA As Range
Dim dataws As Worksheet
Set dataws = Worksheets("Data")
With Worksheets("Data")
Set rngA = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
End With
'CODE TO FIND DUPLICATE DATA
For i = rngA.Count To 1 Step -1 ' Test from bottom of range to 1st row
If dataws.Cells(i, 1).Value = MeasDateMill1 And _
dataws.Cells(i, 2).Value = "Mill 1" Then
Rows(i).Delete
Unload ExistingDataFound
Exit Sub
End If
Next i
End If
'Check if user wants to keep existing value and add another row of data
If ExistingDataFound.KeepExisting.Value = True Then
Unload ExistingDataFound
Exit Sub
End If
'Check if user wants to cancel inputs and start over
If ExistingDataFound.CancelandRevise.Value = True Then
MillMeasurements.MeasDateMill1.Value = ""
MillMeasurements.MeasDateMill2.Value = ""
MillMeasurements.MeasDateCoalMill.Value = ""
Unload ExistingDataFound
Exit Sub
End If
Dim noselect As Long
noselect = MsgBox("No Selection Made", vbOKOnly)
End Sub
2. criteria met in both column A and column B. The code below is linked to
a button on a form with 3 possible selections and the form pops up when data
entered on another form is found to be duplicate to data already existing in
the database. I use similar code to detect "duplicate rows" in the sub that
brings up the selection form and it works.
thanks in advance.
Private Sub OKToProceed_Click()
'Check if user wants to overwrite duplicate data found then delete existing
row
'with duplicate data and go back to mill measurements form
If ExistingDataFound.Overwrite.Value = True Then
'SOMETHING WRONG...THE TEST FOR DUPLICATE ROWS DOESN'T WORK HERE
Dim rngA As Range
Dim dataws As Worksheet
Set dataws = Worksheets("Data")
With Worksheets("Data")
Set rngA = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
End With
'CODE TO FIND DUPLICATE DATA
For i = rngA.Count To 1 Step -1 ' Test from bottom of range to 1st row
If dataws.Cells(i, 1).Value = MeasDateMill1 And _
dataws.Cells(i, 2).Value = "Mill 1" Then
Rows(i).Delete
Unload ExistingDataFound
Exit Sub
End If
Next i
End If
'Check if user wants to keep existing value and add another row of data
If ExistingDataFound.KeepExisting.Value = True Then
Unload ExistingDataFound
Exit Sub
End If
'Check if user wants to cancel inputs and start over
If ExistingDataFound.CancelandRevise.Value = True Then
MillMeasurements.MeasDateMill1.Value = ""
MillMeasurements.MeasDateMill2.Value = ""
MillMeasurements.MeasDateCoalMill.Value = ""
Unload ExistingDataFound
Exit Sub
End If
Dim noselect As Long
noselect = MsgBox("No Selection Made", vbOKOnly)
End Sub