
Originally Posted by
patel
your code works well on my test workbook (excel 2010), also with not blank cells
maybe my code put wrong line ....
Code:
Private Sub buttonnew_Click()
Dim Cancel As Boolean
Dim keyCol As Range
Dim i As Long
Set keyCol = ThisWorkbook.Sheets("Data").Columns(2)
If Me.noinvoice.Value = "" Then
MsgBox "Please enter a name", vbExclamation, "Invoice"
Cancel = True
End If
If Me.Tanggal.Value = "" Then
MsgBox "Please enter a item", vbExclamation, "Invoice"
Cancel = True
End If
If Me.Costumers1.Value = "" Then
MsgBox "Please enter a costumers name", vbExclamation, "Invoice"
Cancel = True
End If
If Me.ttd.Value = "" Then
MsgBox "Please enter a ttd", vbExclamation, "Invoice"
Cancel = True
End If
If Me.initial.Value = "" Then
MsgBox "Please enter a initial", vbExclamation, "Invoice"
Cancel = True
End If
If Cancel = True Then
'Do nothing
Else
For i = 1 To 10
If Me.Controls("item" & i).Text <> vbNullString Then
With keyCol.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).EntireRow
.Columns("L").Value = Me.Controls("item" & i).Text
.Columns("N").Value = Me.Controls("unit" & i).Value
.Columns("K").Value = Me.Controls("type" & i).Text
.Columns("M").Value = Me.Controls("harga" & i).Value
.Columns("P").Value = disc1
.Columns("Y").Value = Me.PajakCode.Value
.Columns("S") = "10%"
.Columns("B") = noinvoice
.Columns("C").Value = Me.Tanggal.Value
.Columns("D").Value = Costumers1
.Columns("V").Value = Note
.Columns("X").Value = ttd
.Columns("W").Value = initial
End With
End If
Next i
Range("AA1").Select
ActiveWindow.ScrollColumn = 1
ActiveWindow.ScrollRow = 1
Unload Me
End If
Worksheets("Data").Columns("M").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub
and can i'm input two columns M & N ? i'm noobs VBA must using columns("M:N") or columns("M"),columns("N) or other suggest.
Thanks - John
Bookmarks