Unable to select multiple cells with CTRL key

peterbatah

New Member
Joined
Jul 17, 2017
Messages
25
Hello all.

I have this bit of code running in my worksheet.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'updateby Extendoffice 20160530
    On Error GoTo LZoom
    Dim xZoom As Long
    xZoom = 100
    If Target.Validation.Type = xlValidateList Then xZoom = 130
LZoom:
    ActiveWindow.Zoom = xZoom
End Sub

The only way that I can select multiple cells using the CTRL key is if I break the running VB code.

Any assistance would be greatly appreciated.

Thank you

Peter
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try the below. We can test the number of selected cells (Target.Count) to see if there is only one cell selected.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
    'updateby Extendoffice 20160530
        On Error GoTo LZoom
        Dim xZoom As Long
        xZoom = 100
        If Target.Validation.Type = xlValidateList Then xZoom = 130
LZoom:
        ActiveWindow.Zoom = xZoom
End If
End Sub
 
Upvote 0
UPDATE: My apologies. I had opened the wrong file which still had my original code.

The code that you provided appears to have solved the issue. Much appreciated!

Thank you so much for the prompt reply MrKowz. I really appreciate it.

Unfortunately, I am experiencing the same issue after replacing my code with the code that you kindly provided.

Try the below. We can test the number of selected cells (Target.Count) to see if there is only one cell selected.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
    'updateby Extendoffice 20160530
        On Error GoTo LZoom
        Dim xZoom As Long
        xZoom = 100
        If Target.Validation.Type = xlValidateList Then xZoom = 130
LZoom:
        ActiveWindow.Zoom = xZoom
End If
End Sub
 
Last edited:
Upvote 0
Are you receiving an error? What is/isn't happening? I tested the theory using the below code, and it only showed me the message box if I had one cell selected.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count = 1 Then
    MsgBox "foo"
End If
End Sub
 
Upvote 0
No error messages. I should have deleted this line from my last response: Unfortunately, I am experiencing the same issue after replacing my code with the code that you kindly provided.


I am now able to select multiple cells when the VB code is running.
 
Upvote 0
No error messages. I should have deleted this line from my last response: Unfortunately, I am experiencing the same issue after replacing my code with the code that you kindly provided.


I am now able to select multiple cells when the VB code is running.

Great - thank you for the feedback. Have a good day!
 
Upvote 0
When you change zoom, you kill Undo, so you might want to do it as infrequently as necessary.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Dim iDV           As XlDVType

  If Target.CountLarge = 1 Then
    On Error Resume Next
    iDV = Target.Validation.Type
    If iDV = 0 Then
      If ActiveWindow.Zoom <> 100 Then ActiveWindow.Zoom = 100
    Else
      If ActiveWindow.Zoom <> 130 Then ActiveWindow.Zoom = 130
    End If
  End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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