macro causing printing problem

ed.ayers315

Board Regular
Joined
Dec 14, 2009
Messages
166
Hi Folks,

Happy Mother's Day!!

The following code is causing issues when I try to set up a print range with a macro. This error pops up
5742011027713639762
Run Time Error '13':

In the code below, the degger stops at the red font

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("g21:h21,g23:h23,g25:h25,e25,g27:h27,g29:h29,g31:h31,g33:h33,g35:h35,g37:h37,g39:h39,g41:h41,g43:h43,g48:h48,g50:h50,g52:h52,g54:h54,g56:h56,g58:h58,g60:h60,g62:h62,g64:h64,g66:h66")) Is Nothing Then
Cancel = True
If VarType(Target.Value) = vbBoolean Then
Target.Value = Not (Target.Value)
Else
Target.Value = IIf(Target.Value = 1, Null, 1)
End If
End If

Dim lZoom As Long
Dim lZoomDV As Long
Dim lDVType As Long
lZoom = 119
lZoomDV = 180
lDVType = 0
Application.EnableEvents = False
On Error Resume Next
lDVType = Target.Validation.Type

On Error GoTo errHandler
If lDVType <> 3 Then
With ActiveWindow
If .Zoom <> lZoom Then
.Zoom = lZoom
End If
End With
Else
With ActiveWindow
If .Zoom <> lZoomDV Then
.Zoom = lZoomDV
End If
End With
End If
exitHandler:
Application.EnableEvents = True
Exit Sub
errHandler:
GoTo exitHandler

ActiveSheet.Calculate
ActiveWindow.SmallScroll
Application.WindowState = Application.WindowState
End Sub
Code:

I do not what is wrong with the code, any suggestions?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Strange because this works for me

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If VarType(Target.Value) = vbBoolean Then
    Target.Value = Not Target.Value
Else
    Target.Value = IIf(Target.Value = 1, vbNullString, 1)
End If
End Sub

Tested with Boolean, numbers (including dates). However it errors if the Target contains an error value like #N/A. Is that a possibility?
 
Upvote 0
I can not find any.

B27:d27 is DV
E27 is DV
G27 is where on select change changes from "1" to "0"
Row b28:e28 is for text
as well as f28:i28

I have 20 or so of this combination down my report.

The error only comes up if these blocks are part of the selected area. Whether or not they have information or blank.
<!-- ######### Start Created Html Code To Copy ########## -->
Excel Workbook
BCDEFGHI
27SupplierCustomer
28
SERVICE_REPORT
<!-- ######### End Created Html Code To Copy ########## -->
 
Upvote 0
If you are selecting multiple cells you need something like

Code:
Dim c As Range
For Each c In Target
    If VarType(c.Value) = vbBoolean Then
        c.Value = Not c.Value
    Else
        c.Value = IIf(c.Value = 1, vbNullString, 1)
    End If
Next c
 
Upvote 0
Oh pooh,

I pasted this code in under this
Code:
If Not Intersect(Target, Range("g21:h21,g23:h23,g25:h25,e25,g27:h27,g29:h29,g31:h31,g33:h33,g35:h35,g37:h37,g39:h39,g41:h41,g43:h43,g48:h48,g50:h50,g52:h52,g54:h54,g56:h56,g58:h58,g60:h60,g62:h62,g64:h64,g66:h66")) Is Nothing Then
Cancel = True
Code:

and it replaced everything with a 1

Where should I paste it?
 
Upvote 0
It (and your original) would replace blanks and text with 1. What should happen with blanks etc.
 
Upvote 0
Try

Rich (BB code):
Dim c As Range
For Each c In Target
    If VarType(c.Value) = vbBoolean Then
        c.Value = Not c.Value
    Else
        If IsNumeric(c.Value) Then c.Value = IIf(c.Value = 1, vbNullString, 1)
    End If
Next c
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,453
Members
448,967
Latest member
grijken

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