I am trying to make a invoicing spreadsheet. The basics are all working and what I have kind of works but I can't seem to figure out the issue.
Here is the code I'm having issues with. I am trying to insert 25 different lines of data but only if they actually have data in them so I don't have a bunch of empty cells. I then would like to sort the data in the table that the data was copied to so it can then be recalled.
My First problem is that the data is not getting copied correctly and it is leaving blank cells in my tables and secondly it is not sorting correctly which could be caused by the invalid copying.
Thank you to anyone willing to help!![]()
Private Sub SubmitAndCloseButton_Click() Dim myNewRow As ListRow Dim myNewRow2 As ListRow Dim wrksht As Worksheet Set wrksht = Worksheets("Data") Dim wrksht2 As Worksheet Set wrksht2 = Worksheets("Invoices - Main") Dim vMax As Integer vMax = Application.WorksheetFunction.Max(wrksht2.Range("A:A")) Dim i As Long vMax = vMax + 1 For i = 1 To 25 With ws If Controls("TotalTextBox" & i).Value = "$0.00" Then i = 25 Else Set myNewRow = wrksht.ListObjects("InvoiceDetails").ListRows.Add(2, True) wrksht.Range("A4").Value = vMax wrksht.Range("B4").Value = Format((Controls("DateTextBox" & i).Value), "DD/MM/YYYY") wrksht.Range("C4").Value = Controls("CustomerPOTextBox" & i).Value wrksht.Range("D4").Value = Controls("YIGPOTextBox" & i).Value wrksht.Range("E4").Value = Format((Controls("TaxTextBox" & i).Value), "Currency") wrksht.Range("F4").Value = Format((Controls("TotalTextBox" & i).Value), "Currency") End If End With Next i Set myNewRow2 = wrksht2.ListObjects("InvoicesMain").ListRows.Add(1, True) wrksht2.Range("A4").Value = vMax wrksht2.Range("B4").Value = Controls("CustomerNameComboBox").Value wrksht2.Range("C4").Value = Date wrksht2.Range("D4").Value = Controls("CreditTextBox").Value With wrksht2.ListObjects("InvoicesMain") .Sort.Rng.Sort Key1:=.Sort.Rng(1, 1), Header:=xlYes, order1:=xlDescending With wrksht.ListObjects("InvoiceDetails").Sort .SortFields.Clear .SortFields.Add Key:=.Rng(1, 1), Order:=xlDescending .SortFields.Add Key:=.Rng(1, 2), Order:=xlAscending .Header = xlYes .Apply End With End With For Each ctrl In Me.Controls If TypeName(ctrl) = "TextBox" Then ctrl.Value = "" 'CLEAR THE VALUE. End If Next ctrl MsgBox "Successfully Entered Receipt", vbInformation, " " vMax = Application.WorksheetFunction.Max(wrksht2.Range("B:B")) InvoiceNumberLabel.Caption = "Invoice#: " & vMax + 1 Unload Me End Sub
Edit:
I also have an issue were added lines of data don't pick up the table formulas.











LinkBack URL
About LinkBacks

Register To Reply

Bookmarks