Type mismatch error when clearing data

rodweston

New Member
Joined
Mar 20, 2008
Messages
10
Office Version
  1. 365
Platform
  1. Windows
When I select two or more rows of data, right-click and select 'Clear Contents' I get a type mismatch error in a macro on the following line:
If Intersect(Target, Range("B5:B200")).Value = "x" Then

How would I prevent this from occurring
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
It triggers Worksheet_Change event again as soon as you write "x" value in the cells.

Try to use like:
VBA Code:
  Application.EnableEvents = False
  Intersect(Target, Range("B5:B200")).Value = "x"
  Application.EnableEvents = True
This will allow you to mute events before writing. Then it allows events again.
 
Upvote 0
.. as soon as you write "x" value in the cells.
The OP's code is not writing "x" in any cells.

@rodweston
When you select 2 or more rows (lets use the 3 rows 10:12 as an example), the intersection of the selection and B5:B200 is B10:12
B10:B12 does not have a value, it has 3 values which cannot together be compared to "x", hence the error.

Can you confirm that this is part of a Worksheet_Change event code and, if so, tell us more about exactly what you are trying to if a cell in column B is changed to "x"?

Also, I suggest that you update your forum profile (click your user name at the top right of the forum, then ‘Account details’) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
I have updated the profile.
If an 'x' is entered in column B, the code calculates and writes data in several other columns in the row.
Emulsion Production Schedule with Raw Materials - Copy.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAE
1A,B,C,D,E,F,G,H,I,J344068.78/12.1220.6322.6828.325.68808162012.12
2
3+H JA004F JR001S JR002 Part 1S JR002 Part 2Tank Group Used to HomogenizeDone Polymerizing dateTank Groups AvailableJR001 Done Gestating DateOrder/ReceiveD4DBSATEOSSodium HydroxideDEA1171A SYL-OFF (TIN)Nalco 1130 Colloidal SilicaNalco 1115 Colloidal SilicaTergitol 15-S-9OH Fluid15% HClCatalystAMP-95Andisil 187Andisil 137TK01JA018KBM 802KBM 803ethyl-hexylacrylateTinuvin 400
4C,D,E,F,G,H,I,J34,788.002,696.00740.401,249.00365.00483.8014,483.3026,816.20183.9038,010.005,488.00274.00245.00475376.8363.891700.7441398.7359.580
5
6
7
8
9
10
11
12
13
current
Cells with Conditional Formatting
CellConditionCell FormatStop If True
N5:N86Cell Value<150textNO
O4:O8,P5:P8,O9:P86,S6:S86Cell Value<44textNO
M5:M86Cell Value<200textNO
S4:S86Cell Value<73textNO
Q5:Q86Cell Value<6600textNO
L4:L86Cell Value<500textNO
R5:R86Cell Value<10500textNO
P4:W4,S5:W5Cell Value<44textNO
 
Upvote 0
Can you confirm that this is part of a Worksheet_Change event code
You didn't address that point but I'm assuming that case.
I suggest that you try code with this structure

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, c As Range
  
  Set Changed = Intersect(Target, Range("B5:B200"))
  If Not Changed Is Nothing Then
    Application.EnableEvents = False
    For Each c In Changed
      If c.Value = "x" Then
        'Put the code here that calculates and writes data in several other columns in the row.
        
      End If
    Next c
    Application.EnableEvents = True
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top