Results 1 to 4 of 4

Thread: Issues with VBA code for a range. I'm getting Type Mismatch Error 13

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    1

    Post Issues with VBA code for a range. I'm getting Type Mismatch Error 13

    The code below works for an individual cell, but I get type mismatch when i want to implement this for a range. Would appreciate it if someone can make the below work. Thanks.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Range("A159:A1034").Value = "SC" Then
    Range("J159:J1034").Value = "SC:NA"

    Else
    Range("J159:J1034").Value = Null
    End If

    End Sub

  2. #2
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Issues with VBA code for a range. I'm getting Type Mismatch Error 13

    What line does it break on (which is the error line) ?
    If you really wish a speedy solution, why not make a pruned down copy of it, and attach it ?

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Issues with VBA code for a range. I'm getting Type Mismatch Error 13

    Another idea: Post in the correct forum?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Issues with VBA code for a range. I'm getting Type Mismatch Error 13

    you can not return the values of a range of multiple cells to a single result as an array would be returned, hence a type mismatch
    conversely you can assign a single value to an range of multiple cells

    if you need to check all the cells in the range specified, you could use countif worksheet function try
    Code:
    If WorksheetFunction.CountIf(range("a159:a1034"),"SC")= WorksheetFunction.CountA(range("a159:a1034")) Then
    Last edited by westconn1; Apr 5th, 2021 at 06:59 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width