开发者

Next non-blank cell in excel/visualBasic

I'm trying to script a very basic set of keystrokes in excel where I'm setting a cell to reference a cell 开发者_JAVA百科that is 2 to the right and then the next non-blank cell down. Very easy set of keystrokes:

= right right ctrl-down enter

But when I use the macro recorder to do this it wants to substitute the ctrl-down with a relative reference; ie

ActiveCell.FormulaR1C1 = "=R[6]C[3]"

Surely there is an easy substitution to do what I want?


dim Rng as range
set Rng=Activecell.offset(0,2).end(xldown)

is the equivalent of your key-strokes, but its not the next non-blank cell, its the last contiguous non-empty cell


Worth noting that Charles' answer will take you to the last cell with something in it before a blank cell. There could be more detail below the blank cell. When I look for the last cell in a row, I start from the bottom and work my way up.

Working from the active cell it would look like this:

Dim col As Double
Dim rw As Double
col = ActiveCell.Column + 2
rw = 65000
Debug.Print col & "-" & rw
Cells(rw, col).End(xlUp).Select


Worth noting that Charles' answer will take you to the last cell with something in it before a blank cell. There could be more detail below the blank cell. When I look for the last cell in a row, I start from the bottom and work my way up.

Working from the active cell it would look like this:

Dim col As Double
Dim rw As Double
col = ActiveCell.Column + 2
rw = 65000
Cells(rw, col).End(xlUp).Select
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜