Results 1 to 5 of 5

Trying to add form data to a table and then sort the data.

Threaded View

NathGamer Trying to add form data to a... 06-15-2019, 05:51 PM
BadlySpelledBuoy Re: Trying to add form data... 06-16-2019, 03:20 AM
NathGamer Re: Trying to add form data... 06-18-2019, 10:37 PM
Pepe Le Mokko Re: Trying to add form data... 06-19-2019, 02:34 AM
NathGamer Re: Trying to add form data... 06-19-2019, 10:35 PM
  1. #1
    Registered User
    Join Date
    06-15-2019
    Location
    Whitehorse, Canada
    MS-Off Ver
    microsoft office 2013
    Posts
    5

    Trying to add form data to a table and then sort the data.

    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.

    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
    Thank you to anyone willing to help!


    Edit:
    I also have an issue were added lines of data don't pick up the table formulas.
    Attached Files Attached Files
    Last edited by NathGamer; 06-25-2019 at 11:39 AM. Reason: Another Issue

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Alternative to VLOOKUP when data is in min/ max (i.e. 0-5) form vs. table form
    By kelseygueldalewis in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-23-2017, 10:58 AM
  2. VBA Code to Sort Data from a User Form
    By lateniteNC1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2017, 02:22 PM
  3. VBA code to copy data from Excel data table to user form
    By Srikanth H N in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-03-2014, 11:53 AM
  4. Require VBA code to Get data from data table to user form using command button
    By Srikanth H N in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-01-2014, 04:17 PM
  5. Replies: 1
    Last Post: 03-15-2013, 01:25 PM
  6. Replies: 0
    Last Post: 02-04-2012, 05:17 AM
  7. Replies: 1
    Last Post: 09-26-2007, 12:47 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1