-
Apr 3rd, 2021, 06:46 PM
#1
Thread Starter
New Member
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
-
Apr 4th, 2021, 01:04 AM
#2
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 ?
-
Apr 4th, 2021, 09:00 AM
#3
Re: Issues with VBA code for a range. I'm getting Type Mismatch Error 13
Another idea: Post in the correct forum?
-
Apr 5th, 2021, 06:20 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|