Confused

topi1

Active Member
Joined
Aug 6, 2014
Messages
252
Office Version
  1. 2010
I am really confused.

I am running the following macro.

Rich (BB code):
Sub StartNew()
'
' StartNew Macro
'
'
    Range("E29,E30,J30,J29,L29,L30").Select
    Range("L30").Activate
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("B28").Select
    Selection.Copy
    Range("B28,N25,N26,N27,N28").Select
    Range("N28").Activate
    ActiveSheet.Paste
    Range("B72").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("B72,E25,J25,L25").Select
    Range("L25").Activate
    ActiveSheet.Paste
   Range("B30:B33").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("D19").Select
    ActiveSheet.Paste
    Range("B35:B47").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("D3:D15").Select
    Range("D15").Activate
    ActiveSheet.Paste
    Range("B9").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("B9,O16,O20").Select
    Range("O20").Activate
    ActiveSheet.Paste
    Range("O4:O15").Select
    Application.CutCopyMode = False
    Selection.ClearContents
    Range("O4").Select
End Sub
However, I get the error message #13 and says type mismatch. When I hit debug, the following red line is highlighted from a separate macro which I have in the worksheet.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
[COLOR=#FF0000] If Target.Value = "No" Then[/COLOR]
 Target = "Yes"
 ElseIf Target.Value = "Yes" Then
 Target = "No"
 End If
 End Sub
Any solution?
Thanks.
 
Last edited by a moderator:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I would guess it's because the Selection Change event handler fires when you select six non-contiguous cells. It then tries to compare the Target (six cells) to the single value "No".

You should avoid all the Selecting you do; it's not necessary to select something to copy or manipulate it.
 
Upvote 0
Thanks for your reply. I am not sure how to reset the fields (some of which are data validation drop down containing cells) without selecting, copying and pasting.
 
Upvote 0
What TMS is suggesting is for example, your first 6 lines of code can be reduced to
Code:
Range("E29,E30,J30,J29,L29,L30").Select
Range("L30").Activate
Application.CutCopyMode = False
Selection.ClearContents
Range("B28").Select
Selection.Copy

TO

Range("E29,E30,J30,J29,L29,L30").ClearContents
Range("B28").Copy
 
Upvote 0
Code:
Range("E29,E30,J30,J29,L29,L30").ClearContents
Range("B28").Copy Range("B28,N25,N26,N27,N28")
Range("B72").Copy Range("B72,E25,J25,L25")
' etc

(first 15 lines)
 
Last edited:
Upvote 0
@TMS....I didn't know we were going to do the whole thing...:lol:
 
Upvote 0
@Michael: I didn't intend to ... just got on a roll ;). I wanted to give a couple of examples. There's still the second half for the OP to have a go at.
 
Upvote 0
Thank you both much. Greatly appreciated. I am okay with excel but do not know VBA. As you must have figured out, I just recorded my actions and created the macro.I will try your suggestions. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,899
Messages
6,181,627
Members
453,058
Latest member
rmd0725

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