+ Reply to Thread
Results 1 to 3 of 3

add and delete rows from Tables

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-06-2020
    Location
    Adelaide
    MS-Off Ver
    MS Office 365
    Posts
    108

    add and delete rows from Tables

    Hi,

    I seem to be missing something as I am getting an error when trying to add a row to a tmp table I have created.

    The excel work Mock- Control is where my code is.
    The excel Mock-Statement has a button to randomly generate an invoice number and the amounts.

    I keep getting an objecting error.

    I appreciate any help.
    Attached Files Attached Files

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,411

    Re: add and delete rows from Tables

    why not contain it all in one workbook. ????
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  3. #3
    Registered User
    Join Date
    03-19-2022
    Location
    TBD
    MS-Off Ver
    O365
    Posts
    46

    Re: add and delete rows from Tables

    Hi Oberon70

    You have to edit the Sub AddInvToArray, the error is at myNewRow = rngInvNum.Cells(rw, 1).Value because myNewRow is ListRow data type.
    Please change to myNewRow.Range.Columns(1) = rngInvNum.Cells(rw, 1).Value

    Also, I think you need to add a new row after inserting, if not, then the new value will overwrite the older value.
    My suggestion as below.

    Sub AddInvToArray()
    
    Dim myNewRow As ListRow
    
    Set myNewRow = LoTempTbl.ListRows.Add
    
    
        x = 1
        RAgent = "Wayne Enterprise"
        
        For rw = rngAgent.Rows.Count To 1 Step -1
            If rngAgent.Cells(rw, 1) = RAgent And _
                rngReceipt.Cells(rw, 1) = "" And _
                rngBatchRpt.Cells(rw, 1) = "" _
                Then
                    ' Do something
                   ' LoInvNum.Add = rngInvNum.Cells(rw, 1).Value
                    Debug.Print rngInvNum.Cells(rw, 1).Value
                    'rngTempTbl.Cells(x).Value = rngInvNum.Cells(rw, 1).Value
                    
                    myNewRow.Range.Columns(1) = rngInvNum.Cells(rw, 1).Value
                    Set myNewRow = LoTempTbl.ListRows.Add              
                    
                    
                    
                    x = x + 1
        
            End If
                
        Next rw
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Delete Blank rows between tables and keep one row.
    By redahussien in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-25-2021, 05:02 PM
  2. Replies: 2
    Last Post: 12-07-2020, 06:42 AM
  3. Delete and add rows to multiple tables on multiple sheets using inputbox
    By Oliver_watkins in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-03-2020, 04:56 AM
  4. Delete blank/empty rows between two pivot tables
    By curious4 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-04-2018, 01:45 PM
  5. Rows delete formula as per range of cell values with counter to delete # rows
    By qureshi2016 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-03-2017, 09:35 AM
  6. [SOLVED] DELETE empty rows, from two tables?
    By B.W.B. in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-02-2016, 11:29 AM
  7. Replies: 0
    Last Post: 04-18-2005, 12:07 AM

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