Vba: Stop Data Entry sheet Entering data if checkbox is set to False

Sirico

New Member
Joined
Sep 29, 2021
Messages
10
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
  2. Web
Hey everyone,

Been lurking a while
Just joined, first post

I'm having an issue with a data entry sheet I am designing. I have kind of hacked together a function that copies the forms data and selected size. I'm trying to have it do this for any size set to true, but currently if it's set to false it is still pasting in the form data on the next line.

Code:

VBA Code:
''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

                                     ''''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 _
    )
'Checkbox data entry

If Me.CheckBox0k.Value = True Then ws.Range("I" & RowInsert).Value = "0k"
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

                                     ''''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 _
    )
End With


 If Me.CheckBox05k.Value = False Then ws.Range("I" & RowInsert).Value = "0k"
If Me.CheckBox05k.Value = True Then ws.Range("I" & RowInsert).Value = "0.5k"
Exit Sub

End With




Set ws = Nothing
End Sub

excel
vba
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
The writing to the cells is not inside the IF statement regarding the checkbox value so gets written every time
maybe this
VBA Code:
'Checkbox data entry
With ws
    If Me.CheckBox0k.Value = True Then
        .Range("I" & RowInsert).Value = "0k"
        LastRow = .Cells(Rows.Count, "A").End(xlUp).Row

        RowInsert = .Range("A1:A" & LastRow).Find("*", .Cells(LastRow, "A"), xlValues, , , xlPrevious).Row
        RowInsert = RowInsert + 1
    
                                         ''''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)
            
        If Me.CheckBox05k.Value = False Then ws.Range("I" & RowInsert).Value = "0k"
        If Me.CheckBox05k.Value = True Then ws.Range("I" & RowInsert).Value = "0.5k"
            
    End If
End With
 
Upvote 0
Solution
The writing to the cells is not inside the IF statement regarding the checkbox value so gets written every time
maybe this
VBA Code:
'Checkbox data entry
With ws
    If Me.CheckBox0k.Value = True Then
        .Range("I" & RowInsert).Value = "0k"
        LastRow = .Cells(Rows.Count, "A").End(xlUp).Row

        RowInsert = .Range("A1:A" & LastRow).Find("*", .Cells(LastRow, "A"), xlValues, , , xlPrevious).Row
        RowInsert = RowInsert + 1
   
                                         ''''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)
           
        If Me.CheckBox05k.Value = False Then ws.Range("I" & RowInsert).Value = "0k"
        If Me.CheckBox05k.Value = True Then ws.Range("I" & RowInsert).Value = "0.5k"
           
    End If
End With
Thnak you
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top