如何搜索前5个连续空白单元格的特定行?

时间:2017-11-16 16:12:51

标签: excel vba excel-vba

我无法弄清楚如何在F列后的特定行中找到前5个连续的空白单元格。

通过在Sheet2中的列B中搜索从Sheet1的单元格A1中的下拉列表中选择的值来找到特定的行号:

library(dplyr)
library(purrr)
library(pryr)
my_fun2 <- function(...,x,y){
  dots0 <- as.character(substitute(alist(...)))[-1]
  vectors <- substr(dots0,1,2) == "c("
  dotsv <- dots0[vectors] %>%
    gsub("\"","",.)    %>% 
    gsub("(","('",.,fixed=TRUE)   %>% 
    gsub(", ","', '",.,fixed=TRUE)  %>%
    gsub(")","')",.,fixed=TRUE)  %>%
    map(~eval(parse(text=.x)))
  setNames(c(as.list(dots0[!vectors]),dotsv),names(pryr::dots(...)))
}

identical(my_fun2("a",foo= "b == 3",c("c","d"),bar = c("e","f"),c("g","h")),
my_fun2("a",foo= b == 3,c("c","d"),bar = c("e",f),c(g,h)))
# [1] TRUE

# [[1]]
# [1] "a"
# 
# $foo
# [1] "b == 3"
# 
# [[3]]
# [1] "c" "d"
# 
# $bar
# [1] "e" "f"
# 
# [[5]]
# [1] "g" "h"

如何在F列后的前5个连续空白单元格中搜索targetRow?

1 个答案:

答案 0 :(得分:1)

也许是这样。使用SpecialCells查找空白区域。它恰好是5个空白还是至少5个?

Sub x()

Dim myValue As Range 'value selected from a drop down list
Dim findRow As Range
Dim targetRow As Long
Dim r As Range

Set myValue = Sheets("Sheet1").Range("A1") 'location of drop down list
Set findRow = Sheets("Sheet2").Range("B:B").Find(What:=myValue, LookIn:=xlValues) 'searches column B in Sheet2 for the selected drop down list value
If Not findRow Is Nothing Then
    targetRow = findRow.Row
    With Sheets("Sheet2")
        For Each r In .Range(.Cells(targetRow, "F"), .Cells(targetRow, .Columns.Count)).SpecialCells(xlCellTypeBlanks).Areas
            If r.Count = 5 Then
                MsgBox r.Address
                Exit Sub
            End If
        Next r
    End With
End If

End Sub