获取下一个空行的数量

时间:2016-05-20 07:08:41

标签: excel vba excel-vba

我想获取从声明的单元格计算的下一个空行的数量: 正如您所看到的,这是问题所在: get N° 7 declared cell is "A4"

我这样做但是没有得到正确答案: VBA Code1

Sub sup_rapp1()
'*variables
Dim CELDEB As Range, LIGNEFIN As Long, COLONEFIN As Long, WS As Worksheet
'set objet : affecter les objets
Set WS = Sheets("TAB1")
Set CELDEB = Range("A4")
'derniere ligne at colonne of data
LIGNEFIN = WS.Cells(WS.Rows.Count, CELDEB.Column).End(xlUp).Row
MsgBox LIGNEFIN

wronge reponse Code 1

Code2

Sub sup_rapp1()
'*variables
Dim CELDEB As Range, LIGNEFIN As Long, COLONEFIN As Long, WS As Worksheet
'set objet : affecter les objets
Set WS = Sheets("TAB1")
Set CELDEB = Range("A4")
'derniere ligne at colonne of data
LIGNEFIN = WS.Cells(WS.Rows.Count, CELDEB.Column).End(xlDown).Row
MsgBox LIGNEFIN

wrong reponse code 2

1 个答案:

答案 0 :(得分:1)

我认为这就是你要找的东西:

Set WS = Sheets("TAB1")
Set CELDEB = WS.Range("A4")

LIGNEFIN = CELDEB.CurrentRegion.Row + CELDEB.CurrentRegion.Rows.Count

MsgBox CStr(LIGNEFIN)

CurrentRegion为您提供细胞所在区域的边界。

你的代码没有得到正确结果的原因是你选择了工作表上的最后一行然后上升,这给了你11或者当你失败时(你留在最后一行) )它给了你另一个价值。