提示:其他語言是Google翻譯的。 你可以訪問 English 版本。
登入
x
or
x
x
註冊
x

or

如何顯示下拉列表中的第一個項目而不是空白?

doc下拉列表默認為頂端1

工作表中的下拉列表可以幫助我們更輕鬆地輸入數據,我們只需要選擇項目而無需逐個輸入。 但是,有時候,當您單擊下拉列表時,它會首先跳到空白項目而不是第一個數據項目,如下圖所示,這可能是由於刪除列表末尾的源數據導致的。 可能很煩人,您必須滾動回每個空白數據驗證單元的長列表的頂部。 本文將討論如何始終在下拉列表中顯示第一項。

使用數據驗證功能在下拉列表中顯示第一項,而不是空白

使用VBA代碼自動顯示下拉列表中的第一項,而不是空白


箭頭藍色右泡 使用數據驗證功能在下拉列表中顯示第一項,而不是空白


實際上,要完成這項工作,您只需要在創建下拉列表時應用特定公式,請按照以下步驟操作:

1。 選擇要插入下拉列表的單元格,然後單擊 數據 > 數據驗證 > 數據驗證,看截圖:

doc下拉列表默認為頂端2

2。 在彈出 數據驗證 對話框下 設置 標籤,選擇 名單 來自 部分,然後輸入此公式: = OFFSET(Sheet3 $ A $ 1,0,0,COUNTA(Sheet3 $ A:!$ A)-1,1)資源 文本框,看截圖:

備註:在這個公式中, Sheet3 該工作表是否包含源數據列表和 A1 是列表中的第一個單元格值。

doc下拉列表默認為頂端3

3。 然後點擊 OK 按鈕,現在,當您單擊下拉列表單元格時,第一個數據項始終顯示在頂部,源數據末尾是否有單元格值被刪除,請參閱截圖:

doc下拉列表默認為頂端4


箭頭藍色右泡 使用VBA代碼自動顯示下拉列表中的第一項,而不是空白

在這裡,我還可以介紹一個VBA代碼,它可以幫助您在單擊數據驗證單元格時自動在下拉列表中顯示第一項。

1。 插入下拉列表後,選擇包含下拉列表的工作表選項卡,然後右鍵單擊以選擇 查看代碼 從上下文菜單中去 Microsoft Visual Basic for Applications 窗口,然後將以下代碼複製並粘貼到模塊中:

VBA代碼:自動顯示下拉列表中的第一個數據項:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Updateby Extendoffice 20160725
    Dim xFormula As String
    On Error GoTo Out:
    xFormula = Target.Cells(1).Validation.Formula1
    If Left(xFormula, 1) = "=" Then
        Target.Cells(1) = Range(Mid(xFormula, 1)).Cells(1).Value
    End If
Out:
End Sub

doc下拉列表默認為頂端5

2。 然後保存並關閉代碼窗口,現在,當您單擊下拉列表單元格時,第一個數據項將立即顯示。


Kutools for Excel解決了您的大多數問題,並使您的生產率提高了80%

  • 重用: 快速插入 複雜的公式,圖表 以及你以前用過的任何東西; 加密單元格 密碼; 創建郵件列表 並發送電子郵件...
  • 超級方程式酒吧 (輕鬆編輯多行文字和公式); 閱讀佈局 (輕鬆讀取和編輯大量單元格); 粘貼到過濾範圍...
  • 合併單元格/行/列 不丟失數據; 分裂細胞含量; 組合重複的行/列...防止重複的細胞; 比較範圍...
  • 選擇複製或唯一 行; 選擇空行 (所有細胞都是空的); 超級查找和模糊查找 在許多工作簿中; 隨機選擇......
  • 精確複製 多個單元格而不更改公式參考; 自動創建參考 多張表; 插入項目符號,複選框等等......
  • 提取文本,添加文本,按位置刪除, 刪除空間; 創建和打印分頁小計; 在單元格內容和註釋之間轉換...
  • 超級過濾器 (將過濾方案保存並應用到其他工作表); 高級排序 按月/週/日,頻率等; 特殊過濾器 用粗體,斜體......
  • 結合工作簿和工作表; 根據鍵列合併表; 將數據拆分為多個表格; 批量轉換xls,xlsx和PDF...
  • 超過300強大的功能。 支持Office / Excel 2007-2019和365。 支持所有語言。 在您的企業或組織中輕鬆部署。 全功能30天免費試用。
kte tab 201905

Office選項卡為Office提供選項卡式界面,使您的工作更輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,Publisher,Access,Visio和Project。
  • 在同一窗口的新選項卡中打開並創建多個文檔,而不是在新窗口中。
  • 通過50%提高您的工作效率,每天為您減少數百次鼠標點擊!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Jason · 4 months ago
    Doesn't work for me. I keep getting an error message that says, "There's a problem with this formula. Not trying to type a formula? When the first character is an equal (+) or minus (-) sign, Exel thinks it's a formula.... To get around this, type an apostrophe (') first..."
  • To post as a guest, your comment is unpublished.
    Justin · 1 years ago
    Hello!

    How can I set a data validation list such that if the drop down value in the cell is deleted, the cell will automatically show a default value (i.e. "-Select-")?

    For example, I have a worksheet with multiple drop down lists that I want to show a default value of "-Select-" once the sheet is opened. A user will select values from the lists that will impact the result of calculations throughout the entire spreadsheet. A user may accidentally "delete" the cell contents of the lists. If this happens, rather than the cell becoming blank, I want the cell to show a default value of "-Select-". This scenario occurs in multiple random locations throughout the spreadsheet, not just in one localized place.

    I was able to find the following VBA code so far, but it only applies the concept over a range, rather than just individual cells that contain drop down lists. The problem with what I have coded so far is that every single blank cell in the range ends up with "-Select-" in it. Some of the lists are in ranges, but some are also scattered throughout the sheet. The problem I'm having with my current code is that every single blank cell in the range ends up with "-Select-" in it. I'm trying to get this to apply over the entire worksheet to ONLY cells that are drop down lists.

    Is what I'm trying to accomplish even possible?

    Example file can be found here:
    https://drive.google.com/file/d/1VoO8VgFs3IJ0ALwqfk0i8gt69UE4vEKW/view?usp=sharing

    Example code:

    Option Explicit

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cel As Range
    ' If Target.Cells.Count > 1 Then Exit Sub 'turning this off allows multiple cells to be selected and deleted at the same time
    If Not Intersect(Target, Range("f2:p17")) Is Nothing Then
    For Each cel In Range("f2:p17")
    Application.EnableEvents = False
    If IsEmpty(cel.Value) Then cel.Value = "-Select-"
    Next cel
    End If
    Application.EnableEvents = True
    End Sub


    Thanks in advance!
  • To post as a guest, your comment is unpublished.
    Justin · 1 years ago
    How can I set a data validation list such that if the drop down value in the cell is deleted, the cell will automatically show the a default value (i.e. "-Select-")?

    For example, I have a worksheet with multiple drop down lists that I want to show a default value of "-Select-" once the sheet is opened. A user will select values from the lists that will impact the result of calculations throughout the entire spreadsheet. A user may accidentally "delete" the cell contents. If this happens, rather than the cell becoming blank, I want the cell to show a default value of "-Select-". This scenario occurs in multiple random locations throughout the spreadsheet, not just in one localized place.

    I was able to come up with the following VBA code so far, but I've only figured out how to apply the concept over a range, rather than just cells that contain a drop down list. The problem with what I have coded so far is that every single blank cell in the range ends up with "-Select-" in it.

    Option Explicit

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cel As Range
    ' If Target.Cells.Count > 1 Then Exit Sub
    If Not Intersect(Target, Range("f2:p17")) Is Nothing Then
    For Each cel In Range("f2:p17")
    Application.EnableEvents = False
    If IsEmpty(cel.Value) Then cel.Value = "-Select-"
    Next cel
    End If
    Application.EnableEvents = True
    End Sub
  • To post as a guest, your comment is unpublished.
    frans eilering · 1 years ago
    select the cell in which you have put the listitem
    the range for the listitem is "Opleiding"
    in your VBA code:

    selection.Value = Range("opleiding").Cells(2, 1)

    the result is that the selected item of the listItem is the second item in the range "Opleiding"
  • To post as a guest, your comment is unpublished.
    DHARAMVIR · 2 years ago
    After scroll down select to cells numeric data not come in series only first cell data come
    select 1,2 different cells and scroll down value not coming 1,2,3,4,5....... only first cell value coming 1,1,1,1,....