VBA如何获取下一个单元格地址

我正在编写一段代码来完成一个循环,我想要做的是将单元格地址J2存储在一个variables中,然后每次代码运行循环时,都要将它放到下一个单元格中,即J2会去J3然后J3J4等等。

这是我一分钟得到的,并尝试过:

 Index = 0 CurrentCell = Range("J2").Address Set objOutlook = CreateObject("Outlook.Application") Set objMail = objOutlook.CreateItem(0) RowsCount = Application.CountA(Range("A3:A" & Rows.Count)) While Index < RowsCount CurrentCell = CurrentCell + 1 Recipients = CurrentCell + ";" Index = Index + 1 Wend 

有人可以请帮忙。

不知道当前的cellcell是干什么的(所以我把它删除了),但set的rng行将被设置为每一行

用下面的代替你的循环

 While Index < RowsCount set rng = range("J2").offset(0+Index,0) Recipients = Recipients & rng.value & ";" Index = Index + 1 Wend 

猜测你想要达到的目标:

 Dim lIndex As Long Dim lLastRow As Long Set objOutlook = CreateObject("Outlook.Application") Set objMail = objOutlook.CreateItem(0) ' find the number of the last populated row in column A lLastRow = Cells(Rows.Count, "A").End(xlUp).Row For lIndex = 2 To lLastRow ' append the values of each cell in column J to a string, separated by semicolons Recipients = Recipients & ";" & Cells(lIndex, "J").Value Next lIndex ' strip off the leading semicolon by taking everything after the first character Recipients = Mid$(Recipients, 2) 

这一行应该分配下一个单元格的地址:

 CurrentCell = Range(CurrentCell).Offset(1, 0).Address