+ Reply to Thread
Results 1 to 6 of 6

Error 13 Mismatch when insert a new row in VBA

  1. #1
    Forum Contributor
    Join Date
    04-08-2023
    Location
    Singapore
    MS-Off Ver
    365, 2021
    Posts
    113

    Error 13 Mismatch when insert a new row in VBA

    Hi,

    i have created an vba script for me in my dropdown list to prompt user when select from it so it will hide an row, however in my business process i may need the user to add in a row in the table, this is where i encounter this issue. can someone help me figure why i got this error issue ?

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by excelvbanew; 04-26-2023 at 10:02 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Error 13 Mismatch when insert a new row in VBA

    The immediate cause of your problem is that if the user inserts a row, it is a Change event for the entire row. That is, if they insert a row at row 5, Target is $5:$5. You need to expand your test:

    Please Login or Register  to view this content.
    However, you have a bigger problem. If you allow the user to insert (or delete) rows, the rows to hide or unhide are no longer 17:22. You need a way to identify these rows without hardcoding the row numbers. Why do you want to hide them?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    04-08-2023
    Location
    Singapore
    MS-Off Ver
    365, 2021
    Posts
    113

    Re: Error 13 Mismatch when insert a new row in VBA

    cos only the 2 selected value Donation to Charity OR DUMPING/DESTRUCTION will make the justification appear else is hidden

    and i was told they can only insert row and not delete row

    since in this case how can i improve my range select now since it will not be in row 19 ??
    Last edited by excelvbanew; 04-26-2023 at 10:45 PM.

  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Error 13 Mismatch when insert a new row in VBA

    Delete/Insert rows within range H2:H999 may trigger the "change" also.
    Use error trap to skip error
    like this:
    PHP Code: 
    On Error Resume Next 
    Code should be:
    PHP Code: 
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim valueJ As Range
    Set valueJ 
    Range("H2:H999")
    If 
    Intersect(TargetvalueJIs Nothing Then Exit Sub
    On Error Resume Next
    If Target.Value "Dumping/Destruction" Or Target.Value "Donation To Charity" Then
        MsgBox 
    "You have selected: " Target.Value
        Rows
    ("17:22").Hidden False
    Else
        
    Rows("17:22").Hidden True
    End 
    If
    End Sub 
    Note:
    Case "Donation To Charity": different between cell datavalidation and code. Try to copy/paste to keep them the same.
    Quang PT

  5. #5
    Forum Contributor
    Join Date
    04-08-2023
    Location
    Singapore
    MS-Off Ver
    365, 2021
    Posts
    113

    Re: Error 13 Mismatch when insert a new row in VBA

    i see but i see that if i insert a row the justifcation box will appear ?

  6. #6
    Forum Contributor
    Join Date
    04-08-2023
    Location
    Singapore
    MS-Off Ver
    365, 2021
    Posts
    113

    Re: Error 13 Mismatch when insert a new row in VBA

    Quote Originally Posted by 6StringJazzer View Post
    The immediate cause of your problem is that if the user inserts a row, it is a Change event for the entire row. That is, if they insert a row at row 5, Target is $5:$5. You need to expand your test:

    Please Login or Register  to view this content.
    However, you have a bigger problem. If you allow the user to insert (or delete) rows, the rows to hide or unhide are no longer 17:22. You need a way to identify these rows without hardcoding the row numbers. Why do you want to hide them?
    I have added the
    Please Login or Register  to view this content.
    However now the last row of the hidden will not be to show unless i manually change it, since the user now only can keep add and not deleting the rows

+ 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. [SOLVED] UBound coll error after converting macro. Runtime error 13. Type mismatch.
    By Elijah in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-30-2020, 05:08 AM
  2. [SOLVED] Insert line chart for specific column in each sheet AND calculate velocity of each line
    By fakhteh in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-16-2020, 02:17 AM
  3. Macro to insert line or remove line depending on cell in column A.
    By cscott109 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-15-2018, 05:02 PM
  4. Replies: 0
    Last Post: 12-14-2018, 08:20 AM
  5. [SOLVED] Runtime error 13 when i insert a line into my sheet
    By BaronVonBeefDip in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-16-2018, 08:25 AM
  6. Replies: 0
    Last Post: 07-29-2014, 11:43 PM
  7. [SOLVED] Where more than 1 line exists in excel transfer - insert line in word report bookmark
    By PippiLaRue in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 03-13-2013, 05:04 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