I hope your weeks are going well.
Currently writing a data entry from in a VBA user form,
It will be using an array of checkboxes to select size which then fills a row with the other data provided when that checkbox is ticked.
I'm currently running into an issue where I don't know what code to run to have the function delete its previous data when the checkbox is unticked.
Private Sub CheckBox0k_Click()
'''Input
Dim ws As Worksheet
Dim LastRow As Long, RowInsert As Long
Set ws = ThisWorkbook.Worksheets("stock")
With ws
LastRow = .Cells(Rows.Count, "A").End(xlUp).row
RowInsert = .Range("A1:A" & LastRow).Find("*", .Cells(LastRow, "A"), xlValues, , , xlPrevious).row
RowInsert = RowInsert 1
'add the uk size input code here
'''Checkbox based search
''Start
If Me.CheckBox0k.Value = True Then
''''This has to match the number of rows input below
.Cells(RowInsert, "A").Resize(1, 8).Value = Array( _
Me.txtDate.Text, _
Me.textboxparentsku.Text, _
Me.textboxsku.Text, _
Me.comboboxbrand.Text, _
Me.comboboxclosure.Text, _
Me.comboboxgender.Text, _
Me.comboboxmaterial.Text, _
Me.comboboxmodel.Text _
)
ws.Range("I" & RowInsert).Value = CheckBox0k.Caption
'This is the code I'm having issues with
ElseIf CheckBox0k.Value = False Then
.Cells(RowInsert, "A").Resize(1, 8).Value = ws.Range("I" & RowInsert).Value = ""
End If
''Finish
Set ws = Nothing
End With
End Sub
A picture of the current UI with the multiple checkboxes
CodePudding user response:
Ok I have sorted it I made a new rule called RowInvert = RowInsert - 1
and put that into FaneDuru's code:
ElseIf Me.CheckBox0k.Value = False Then .Cells(RowInvert, "A").Resize(1, 9).Value = ""
CodePudding user response:
In order to help, we would need to know more about the process. I men, do you need clearing the last 8 entries (columns)? If so, the working solution should be something like
.Cells(RowInsert, "A").Resize(1, - 9).Value = ""
But your code must check if there are data in the first columns of the row to be processed and warn...