我很感激以下方面的帮助......
我正在使用验证列表功能,但我需要人们轻松添加到列表中。所以我录制了一个宏,并将它从一个按钮链接起来,所以他们只需要添加一个新值并单击按钮。问题是我需要它来找到该列中最后一个填充的单元格。我已经在网上和这里看了,但因为我对VBA完全不熟悉,所以我无法弄清楚如何编辑它。
这是代码,我需要它来选择D4到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
谢谢!
答案 0 :(得分:0)
不确定这是否是你想要的,但这里是用于查找列中最后一个(底部)填充单元格的代码。将其称为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 :(得分:0)
有两种简单的方法可以解决这个问题。
Offset()
只需将您的列表放在另一张admin/config/list
表上,即可将其排除在外。
如果您搜索Excel 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/