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:
And checkbox macro:
i hope you can understand what is my intention.
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.