Value selection in excel

If you work with a large table and you need to search for unique values in Excel that corresponding to a specific request, then you need to use the filter. But sometimes we need to select all the lines that contain to certain values in relation to other lines. In this case, you should use the conditional formatting, which refers to the values of the cells with the query. To get the most effective result, we will use the drop-down list as a query. This is very convenient if you need to frequently change the same type of query to expose of the different table`s rows. We`ll look detailed below: how to make the selection of duplicate cells from the drop-down list.



Selection of the unique and duplicate values in Excel

For example, we take the history of mutual settlements with counterparties, as shown in the picture:

For example.

In this table, we need to highlight in color to all transactions for a particular customer. To switch between clients, we will use the drop-down list. Therefore, in the first place, you need to prepare the content for the drop-down list. We need all the customer names from the column A, without repetitions.

Before selecting to the unique values in Excel, we need to prepare the data for the drop-down list:

  1. Select to the first column of the table A1:A19.
  2. Select to the tool: «DATA»-«Sort and Filter»-«Advanced».
  3. Advanced Filter.

  4. In the «Advanced Filter» window that appears, you need to turn on «Copy the result to another location», and in the field «Place the result in the range:» to specify $F$1.
  5. Place the result.

  6. Tick by the check mark to the item «Unique records only» and click OK.

Unique records only.

As a result, we got the list of the data with unique values (names without repetitions).



Now we need to slightly modify to our original table. To scroll the first 2 lines and select to the tool: «HOME»-«Cells»-«Insert» or to press the combination of the hot keys CTRL + SHIFT + =.

Insert Rows.

We have added 2 blank lines. Now we enter in the cell A1 to the value «Client:».

It’s time for creating to the drop-down list, from which we will select customer`s names as the query.

Before you select to the unique values from the list, you need to do the following:

  1. In the cell B1 you need to select the «DATA»-«Data tool»-«Data Validation».
  2. Data Validation.

  3. On the «Settings» tab in the «Validation criteria» section, from the drop-down list «Allow:», you need to select «List» value.
  4. List.

  5. In the «Source:» entry field, to put =$F$4:$F$8 and click OK.

Source.

As a result, in the cell B1 we have created the drop-down list of customers` names.

Note. If the data for the drop-down list is in another sheet, then it is better to assign a name for this range and specify it in the «Source:» field. In this case this is not necessary, because all of these data is on the same worksheet.

The selection of the cells from the table by condition in Excel:

  1. Highlight the tabular part of the original settlement table A4:D21 and select the tool: «HOME»-«Styles»-«Conditional Formatting»-«New Rule»-«Use the formula to define of the formatted cells».
  2. formatted cells.

  3. To select unique values from the column you need to enter the formula: =$A4=$B$1 in the input field and click on the «Format» button to highlight the same cells by color. For example, it will be green color. And to click OK in all are opened windows.

fill green.

It is done!

is done example unique values.

How does work the selection of unique Excel values? When choosing of any value (a name) from the drop-down list B1, all rows that contain this value (name) are highlighted by color in the table. To make sure of this, in the drop-down list B1 you need to choose to a different name. After that, other lines will be automatically highlighted by color. Such table is easy to read and analyze now.

Download example selection from list with conditional formatting.

The principle of automatic highlighting of lines by the query criterion is very simple. Each value in the column A is compared with the value in cell B1. This allows you to find unique values in the Excel table. If the data is the same, then the formula returns to the meaning TRUE and for the whole line is automatically assigned to the new format. In order for the format to be assigned to the entire line, and not just for the cell in column A, we use the mixed reference in the formula =$A4.

Свойство Selection объекта Application, которое применяется в VBA для возвращения выбранного объекта на активном листе в активном окне приложения Excel.

Свойство Selection объекта Application возвращает выбранный в настоящее время объект на активном листе в активном окне приложения Excel. Если объект не выбран, возвращается значение Nothing.

Если выделить на рабочем листе диапазон «B2:E6», то обратиться к нему из кода VBA Excel можно через свойство Selection объекта Application, например, присвоить выбранный диапазон объектной переменной:

Sub Primer1()

Dim myRange As Object

    Set myRange = Selection

    MsgBox myRange.Address

End Sub

При использовании свойства Selection в коде VBA Excel указывать объект Application не обязательно. Результат работы кода:

На рабочем листе Excel может быть выбран не только диапазон ячеек, но и другие объекты: рисунок, надпись, диаграмма, элемент управления формы и другие.

Применение функции TypeName

Для программного выбора объекта в VBA Excel используется метод Select, а для определения типа ранее выбранного объекта — функция TypeName.

TypeName — это функция, которая возвращает данные типа String, предоставляющие информацию о типе переменной или типе объекта, присвоенного объектной переменной.

Выберем диапазон «D5:K9» методом Select и определим тип данных выбранного объекта с помощью функции TypeName:

Sub Primer2()

    Range(«D5:K9»).Select

    MsgBox TypeName(Selection)

End Sub

В качестве переменной для функции TypeName здесь используется свойство Selection. Результат работы кода:

Следующий пример кода VBA Excel очень хорошо иллюстрирует определение типа выбранного объекта с помощью функции TypeName. Он взят с сайта разработчиков, только в блок Select Case добавлены еще два элемента Case:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

Sub TestSelection()

    Dim str As String

    Select Case TypeName(Selection)

        Case «Nothing»

            str = «Объект не выбран.»

        Case «Range»

            str = «Выбран диапазон: « & Selection.Address

        Case «Picture»

            str = «Выбран рисунок.»

        Case «ChartArea»

            str = «Выбрана диаграмма.»

        Case «TextBox»

            str = «Выбрана надпись.»

        Case Else

            str = «Выбран объект: « & TypeName(Selection) & «.»

    End Select

    MsgBox str

End Sub

Если из предыдущей процедуры VBA Excel удалить переводы отдельных типов объектов и учесть, что рабочий лист без выбранного объекта встречается редко, то ее можно значительно упростить:

Sub TestSelection2()

    MsgBox «Выбран объект: « & TypeName(Selection) & «.»

End Sub

Пример рабочего листа без выбранного объекта: лист диаграммы, на котором диаграмма не выбрана (выделение снимается кликом по одному из полей вокруг диаграммы). Для такого листа в информационном окне MsgBox будет выведено сообщение: Выбран объект: Nothing.

Свойство Selection при выборе листа

Если метод Select применить к рабочему листу, то свойство Application.Selection возвратит объект, который ранее был выбран на данном листе. Проверить это можно с помощью следующего примера:

Sub Primer3()

    Worksheets(3).Select

    Select Case TypeName(Selection)

        Case «Range»

            MsgBox «Выбран диапазон: « & Selection.Address

        Case Else

            MsgBox «Выбран объект: « & TypeName(Selection) & «.»

    End Select

End Sub

Свойство Selection при выборе книги

Выбрать рабочую книгу Excel методом Select невозможно, так как у объекта Workbook в VBA нет такого метода. Но мы можем выбрать книгу, сделав ее активной с помощью метода Activate:

Sub Primer4()

    Workbooks(«Книга2.xlsx»).Activate

    Select Case TypeName(Selection)

        Case «Range»

            MsgBox «Выбран диапазон: « & Selection.Address

        Case Else

            MsgBox «Выбран объект: « & TypeName(Selection) & «.»

    End Select

End Sub

В данном случае, свойство Application.Selection возвратит объект, который ранее был выбран на активном листе активированной книги.

Обычно, свойство Application.Selection используется для работы с выделенным диапазоном ячеек, а для обращения к одной активной ячейке используется свойство Application.ActiveCell.


Select cell contents in Excel

In Excel, you can select cell contents of one or more cells, rows and columns.

Your browser does not support video. Install Microsoft Silverlight, Adobe Flash Player, or Internet Explorer 9.

Note: If a worksheet has been protected, you might not be able to select cells or their contents on a worksheet.

Select one or more cells

  1. Click on a cell to select it. Or use the keyboard to navigate to it and select it.

  2. 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.

  3. To select non-adjacent cells and cell ranges, hold Ctrl and select the cells.

Select one or more rows and columns

  1. Select the letter at the top to select the entire column. Or click on any cell in the column and then press Ctrl + Space.

  2. Select the row number to select the entire row. Or click on any cell in the row and then press Shift + Space.

  3. To select non-adjacent rows or columns, hold Ctrl and select the row or column numbers.

Select table, list or worksheet

  1. To select a list or table, select a cell in the list or table and press Ctrl + A.

  2. To select the entire worksheet, click the Select All button at the top left corner.

    Select All button

Note: In some cases, selecting a cell may result in the selection of multiple adjacent cells as well. For tips on how to resolve this issue, see this post How do I stop Excel from highlighting two cells at once? in the community.

To select

Do this

A single cell

Click the cell, or press the arrow keys to move to the cell.

A range of cells

Click the first cell in the range, and then drag to the last cell, or hold down SHIFT while you press the arrow keys to extend the selection.

You can also select the first cell in the range, and then press F8 to extend the selection by using the arrow keys. To stop extending the selection, press F8 again.

A large range of cells

Click the first cell in the range, and then hold down SHIFT while you click the last cell in the range. You can scroll to make the last cell visible.

All cells on a worksheet

Click the Select All button.

Select All button

To select the entire worksheet, you can also press CTRL+A.

Note: If the worksheet contains data, CTRL+A selects the current region. Pressing CTRL+A a second time selects the entire worksheet.

Nonadjacent cells or cell ranges

Select the first cell or range of cells, and then hold down CTRL while you select the other cells or ranges.

You can also select the first cell or range of cells, and then press SHIFT+F8 to add another nonadjacent cell or range to the selection. To stop adding cells or ranges to the selection, press SHIFT+F8 again.

Note: You cannot cancel the selection of a cell or range of cells in a nonadjacent selection without canceling the entire selection.

An entire row or column

Click the row or column heading.

Worksheet headings

1. Row heading

2. Column heading

You can also select cells in a row or column by selecting the first cell and then pressing CTRL+SHIFT+ARROW key (RIGHT ARROW or LEFT ARROW for rows, UP ARROW or DOWN ARROW for columns).

Note: If the row or column contains data, CTRL+SHIFT+ARROW key selects the row or column to the last used cell. Pressing CTRL+SHIFT+ARROW key a second time selects the entire row or column.

Adjacent rows or columns

Drag across the row or column headings. Or select the first row or column; then hold down SHIFT while you select the last row or column.

Nonadjacent rows or columns

Click the column or row heading of the first row or column in your selection; then hold down CTRL while you click the column or row headings of other rows or columns that you want to add to the selection.

The first or last cell in a row or column

Select a cell in the row or column, and then press CTRL+ARROW key (RIGHT ARROW or LEFT ARROW for rows, UP ARROW or DOWN ARROW for columns).

The first or last cell on a worksheet or in a Microsoft Office Excel table

Press CTRL+HOME to select the first cell on the worksheet or in an Excel list.

Press CTRL+END to select the last cell on the worksheet or in an Excel list that contains data or formatting.

Cells to the last used cell on the worksheet (lower-right corner)

Select the first cell, and then press CTRL+SHIFT+END to extend the selection of cells to the last used cell on the worksheet (lower-right corner).

Cells to the beginning of the worksheet

Select the first cell, and then press CTRL+SHIFT+HOME to extend the selection of cells to the beginning of the worksheet.

More or fewer cells than the active selection

Hold down SHIFT while you click the last cell that you want to include in the new selection. The rectangular range between the active cell and the cell that you click becomes the new selection.

Need more help?

You can always ask an expert in the Excel Tech Community or get support in the Answers community.

See Also

Select specific cells or ranges

Add or remove table rows and columns in an Excel table

Move or copy rows and columns

Transpose (rotate) data from rows to columns or vice versa

Freeze panes to lock rows and columns

Lock or unlock specific areas of a protected worksheet

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Here's how select a value from a list of values from a worksheet's a Validation List. You can use the list to display interactive data in reports.Excel provides two ways to select a value from a list of values. I often use this feature in interactive Excel reports to select dates, regions, products, and other settings.

Below, for example, the dropdown list box in cell C3 allows users to select any of the five products in the list.

The list is easier to maintain if you name it. Here, I named the list MyList. To assign the label in cell A2 as the name of the list below it, first select the range A2:A7. Then, in the Formulas, Defined Names group, choose Create from Selection.

You can use a validation list like this to select items from a list of items in Excel.In the Create Names dialog, make sure that only Top Row is checked, then choose OK.

To set up the list, select the cell where you want the list box to be, and then in the Data, Data Tools group, choose Data Validation, Data Validation.

In the Settings tab of the Data Validation dialog, choose List in the Allow list box. In the Source ref-edit box, enter…
=MyList
…if you want to use a range name. Otherwise, click in the cell and then select the list. Doing so will return the cell reference of the list. Then choose OK.

Initially, the cell in the list box will be unchanged. To change it, click on the arrow to the right of the cell and select a new value, as shown above.

There aren’t many limitations to this method. The list can be in a different worksheet, even in a different workbook. The list can be in a row or a column. And if the list contains more than eight cells, Excel adds a scrollbar to the dropdown list box.

There’s a way to make an Excel cell kind of a dropdown selection box. You would just go to Data->Validation with a cell or a range of cell selected, select list as the data type and specify the list of values.

I would like the dropdown be a multi value select, kind of a multi value lookup.
I suppose there’s no built in support for that, but there may be some third party solutions utilizing the macro capabilities. Googling gave me an example of such a macro but it is far from the experience of a real multi value lookup when you just mark the selected items with check boxes to the left or select the values in a kind of a popup window. (You would select the items needed from a single-value dopdown ny sequentially selecting each item and the macro would populate an adjacent range of cells with the selected values, putting every value in a new cell).

What’s is the most native looking way to make a multi-selection cell in Excel?

studiohack's user avatar

studiohack

13.5k19 gold badges85 silver badges118 bronze badges

asked Jul 25, 2009 at 19:44

axk's user avatar

See the Forms section in Excel Help for the topic «Add a list box or combo box to a worksheet».

From that page (referring to a Form control list box):

Note: If you set the selection type to
Multi or Extend, the cell that is
specified in the Cell link box returns
a value of 0 and is ignored. The Multi
and Extend selection types require the
use of Microsoft Visual Basic for
Applications (VBA) code. In these
cases, consider using the ActiveX list
box control.

And referring to an ActiveX control list box:

To create a list box with multiple
selection or extended-selection
enabled, use the MultiSelect property.
In this case, the LinkedCell property
returns a #N/A value. You must use VBA
code to process the multiple
selections.

answered Jul 25, 2009 at 21:59

Dennis Williamson's user avatar

Dennis WilliamsonDennis Williamson

105k19 gold badges164 silver badges187 bronze badges

1

Понравилась статья? Поделить с друзьями:
  • Value of address function excel
  • Value not available excel
  • Value is derived from which word
  • Value in words in excel
  • Value in excel hide