check box copies an assigned row

PWSY86

New Member
Joined
Nov 22, 2015
Messages
48
Hi,

I have worksheet where i can create new positions using user form. When I add my data (range C:E) also check box is created in column B. Is it possible to make universal macro which will be assigned to new check box and will always copy data range(C:E) in row where check box is created to other sheet. I can do it manualy but when i have 100+ records it's worthless

code for userform commandbutton:
Code:
Private Sub CommandButton1_Click()Dim rw As Long
Dim rw1 As Long
Dim rw2 As Long
Dim LastRow As Long
Dim MyLeft As Double
Dim MyTop As Double
Dim MyHeight As Double
Dim MyWidth As Double
Dim CB As Object


    If TextBox1.Value = "" Then
        Do
            MsgBox ("Nie podano nazwy Dostawcy")
        Loop While TextBox1.Value <> ""
        Exit Sub
    Else
        rw = Sheets("Lista").Range("c2:c" & Rows.count).Cells.SpecialCells(xlCellTypeBlanks).Row
        Sheets("Lista").Range("c" & CStr(rw)) = TextBox1.Value
    End If
 If TextBox2.Value = "" Then
    Do
        MsgBox ("Nie podano nazwy towaru")
    Loop While TextBox2.Value <> ""
 Exit Sub
    Else
        rw1 = Sheets("Lista").Range("d2:d" & Rows.count).Cells.SpecialCells(xlCellTypeBlanks).Row
            Sheets("Lista").Range("d" & CStr(rw1)) = TextBox2.Value
End If
 If TextBox3.Value = "" Then
    Do
        MsgBox ("Nie podano ceny")
    Loop While TextBox3.Value <> ""
 Exit Sub
Else
    rw2 = Sheets("Lista").Range("e2:e" & Rows.count).Cells.SpecialCells(xlCellTypeBlanks).Row
            Sheets("Lista").Range("e" & CStr(rw2)) = TextBox3.Value
End If


LastRow = Sheets("Lista").Range("B2:B" & Rows.count).Cells.SpecialCells(xlCellTypeBlanks).Row
    With Sheets("Lista").Range("B" & CStr(LastRow))
        MyLeft = Cells(LastRow, "B").Left
        MyTop = Cells(LastRow, "B").Top
        MyHeight = Cells(LastRow, "B").Height
        MyWidth = MyHeight = Cells(LastRow, "B").Width
        Set CB = ActiveSheet.CheckBoxes.Add(MyLeft, MyTop, MyWidth, MyHeight)
            With CB
                .Caption = ""
                .Value = xlOff
                .LinkedCell = "B" & LastRow
                .Display3DShading = False
            End With
    End With
End Sub

And checkbox macro:
Code:
Private Sub wybor3()

Dim NextRow As Long
Dim NextRow2 As Long
Dim InpDat As String




    If ActiveSheet.CheckBoxes("ChckBx3").Value = 1 Then
        Application.ScreenUpdating = False
        With Sheets("Matrix")
            If .Range("D18").Value <> "" Then
                MsgBox "Lista jest pełna, przejdź do zamówienia. ", vbExclamation, "Wszystkie pozycje zajęte!"
            Else
            
                Do
                InpDat = InputBox("Podaj ilość:")
            
                    If InpDat = "" Then
                        MsgBox ("Nie podano ilości!")
                        ActiveSheet.CheckBoxes("ChckBx3").Value = 0
                    Else
                        NextRow2 = Sheets("Matrix").Range("G6:G" & Rows.count).Cells.SpecialCells(xlCellTypeBlanks).Row
                        Sheets("Matrix").Range("G" & CStr(NextRow2)) = InpDat
                    End If
                Loop Until InpDat <> ""
            
                Sheets("Lista").Range("C3:E3").Copy
                With Sheets("Matrix")
                    NextRow = .Range("D6:D" & Rows.count).Cells.SpecialCells(xlCellTypeBlanks).Row
                    With .Range("D" & CStr(NextRow))
                            .PasteSpecial Paste:=xlPasteColumnWidths
                            .PasteSpecial Paste:=xlPasteValuesAndNumberFormats
                    End With
                End With
                Application.CutCopyMode = False
                Application.ScreenUpdating = True
            End If
        End With
    End If
End Sub


i hope you can understand what is my intention.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,215,669
Messages
6,126,125
Members
449,293
Latest member
yallaire64

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