I am wondering how I can check if more than one cell is celected in a range?
I have 3 cells i want to check the Ranges are "A:B" and also "D", and im trying this code but its not working for me.
If 3 - CountA(range) < 1 Then
How can I do it in anther way?
To check if multiple values match, you can use the AND function with two or more logical tests: AND(cell A = cell B, cell A = cell C, …) In dynamic array Excel (365 and 2021) you can also use the below syntax.
Select one or more cells To select a range, select a cell, then with the left mouse button pressed, drag over the other cells. Or use the Shift + arrow keys to select the range. To select non-adjacent cells and cell ranges, hold Ctrl and select the cells.
Microsoft Help Text States: “If the selection is extended when you click a cell or press keys to move around the worksheet, it may be because you pressed F8 or SHIFT+F8 to extend or add to the selection.
Something like this for selected range:
If 3-Selection.Cells.Count < 1 then
or, if there is possibility that you will have selected really a lot of cells use this one:
If 3-Selection.Cells.Countlarge < 1 Then
If you are using Worksheet_Change(ByVal Target As Range)
or Worksheet_SelectionChange(ByVal Target As Range)
then use this code:
If InStr(Target.Address, ":") > 0 Or InStr(Target.Address, ",") > 0 Or InStr(Target.Address, ";") > 0 Then
This will check if the selected range is for example:
`A1;C1` (Cells A1 and C1 are selected) or
`E1:E4` (E1 to E4 are selected)
Sometimes it is used ";"
and sometimes ","
so that we check both of them.
Instead of Target
you can use the range that you defined in your code, for example:
If InStr(MyRange.Address, ":") > 0 Or InStr(MyRange.Address, ",") > 0 Or InStr(MyRange.Address, ";") > 0 Then
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With