如何检索vba中的第一个非空白单元格和任何dynamic行的值
Set rngFound = Rows(5).Find("*", Cells(Columns.Count, 5), xlFormulas, , xlByColumns, xlNext)
上面的代码给出了types不匹配错误13。
请提醒我做错了什么,或build议任何其他方法做同样的事情。
试试下面的代码,在代码的注释里面的解释:
Dim rngFound As Range Dim LastCol As Long Dim nonBlankCell As Variant With Worksheets("Sheet1") ' <-- modify to your sheet's name ' -- get last column in a specific row by using the Find function -- Set rngFound = .Rows(5).Find(What:="*", Lookat:=xlPart, LookIn:=xlFormulas, _ SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False) If Not rngFound Is Nothing Then ' Find was successful LastCol = rngFound.Column ' get last Column with data nonBlankCell = rngFound.Value End If End With
用Cells(Columns.Count, 5)
Cells(5, Columns.Count).End(xlToLeft)
replaceCells(Columns.Count, 5)
Cells(5, Columns.Count).End(xlToLeft)
以获取
Set rngFound = Rows(5).Find("*", Cells(5, Columns.Count).End(xlToLeft), xlFormulas, , xlByColumns, xlNext)
尝试这个
Sub Find_Cell() Dim rngFound As Range Set rngFound = ThisWorkbook.Sheets("Sheet1").Rows(5).Find(What:="*", LookIn:=xlValues) If rngFound Is Nothing Then MsgBox "All cells are blank." Else MsgBox "First Cell Address: " & rngFound.Address MsgBox "First Cell Value: " & rngFound.Value End If End Sub
如果你还想find一个公式等于空白的非空白单元格,而不是LookIn:=xlValues
使用LookIn:=xlFormulas