Excelselect范围内的最后一个值为更新的列表macros

我会感激下面的帮助….

我正在使用validation列表function,但我需要人们轻松添加到列表中。 所以我logging了一个macros,并将它从一个button链接,所以他们只需要添加一个新的值,然后点击button。 问题是我需要它find该列中最后一个填充的单元格。 我在网上看了这里,但是因为我对VBA是全新的,所以我不知道如何编辑它。

这里是代码,我需要它来selectD列到D列最后填充的值。

Range("F5").Select ActiveCell.SpecialCells(xlCellTypeSameValidation).Select With Selection.Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:="=Filters!$D$4:$D$21" .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "" .InputMessage = "" .ErrorMessage = "" .ShowInput = True .ShowError = True End With Range("G15").Select 

谢谢!!

不知道这是否是你想要的,但这里是代码find最后(底部)填充单元格中的一列。 称为lastRow = findLastRow(yoursheetname,yourcolumnname(如“F:F”或命名列)):

 Option Explicit Function findLastRow(Sheetname As String, ColumnName As String) Dim lastRow As Integer Dim r As Range Dim WS As Worksheet Set WS = Worksheets(Sheetname) lastRow = WS.UsedRange.Rows.Count '* '* Search backwards till we find a cell that is not empty '* Set r = WS.Range(ColumnName).Rows(lastRow) While r.Value = "" Set r = r.Offset(-1, 0) Wend lastRow = r.Row Set WS = Nothing findLastRow = lastRow End Function 

有两个简单的方法来处理这个问题。

  1. 格式化表格
  2. 使用Offset()命名范围Offset()

只要把你的列表(S)在另一个admin/config/list表单,以避免它。

如果您searchExcel dynamic validation list ,这里有几个很好的网站解释如何做到这一点

http://excelsemipro.com/2011/05/a-dynamic-dependent-drop-down-list-in-excel/

http://www.contextures.com/xlDataVal02.html

https://www.extendoffice.com/documents/excel/4021-excel-data-validation-dynamic-range.html

https://chandoo.org/wp/2010/09/13/dynamic-data-validation-excel/

http://www.techrepublic.com/article/pro-tip-create-a-dynamic-validation-control-in-excel/