Well. . . I'm sad to say I couldn't make either of these codes do what I'm trying to accomplish. (You should both know that I'm fairly new to coding. So sometimes my attempts to adapt other people's code to my purposes are crude, and sometimes futile.)
VBA Code:
Public col As Range
Public idx As Long
Private Sub Worksheet_Activate()
Set col = Range("B1:B" & Range("B" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks)
idx = 1
End Sub
Sub cycleThru()
If idx > col.Areas.Count Then idx = 1
col.Areas(idx).Select
idx = idx + 1
End Sub
@Lrobbo, I wasn't quite sure where to put your code, since what I'm trying for is for it to be behind a "Next Blank" button on the Userform that is the primary interface with the workbook (and as such, to be available on all sheets where the Userform is available). (a) First I tried putting the declarations and
_Activate
in the worksheet's code, and
Sub cycleThru
behind the button (even though I was skeptical) but of course it wouldn't work without the declarations. (b) Next I tried putting everything in the worksheet's code, and calling
cycleThru
from the button. But it just said "variable not defined." (c) Then I tried putting a button on the worksheet, just so I could test it out. This time, the result was that it selected the first blank in Column B, and would not budge from there (same result as every other coding I've tried so far). (d) Finally, I tried adapting the code so the whole thing could be a macro called by the button: same results as "c", above.
One odd thing I noticed: on the sheet I was testing this on there happened to be a group of blank cells down the column a bit. I tinkered with the range, to get it starting below B2, and then it moved down and selected the whole group of blank cells (this was true with both "c" and "d" above). But in no case would it move down again when the button was clicked a second time
Another option
VBA Code:
Sub NickVittum()
Dim NxtCell As Range
On Error Resume Next
Set NxtCell = Range("B:B").SpecialCells(xlBlanks)(1)
On Error GoTo 0
If NxtCell Is Nothing Then Set NxtCell = Range("B" & Rows.Count).End(xlUp).Offset(1)
NxtCell.Select
End Sub
Thank you. It seemed like it
ought to work—but, same results: it locked onto the first blank, and wouldn't move from there. I know what I need; I need it, each time a cell is selected, to use the new active cell as the new reference point and move on from there. I just don't know how to make that adaptation. I tried replacing
("B:B")
, in the "SET" line, with (ActiveCell & ":B"). The result was that is skipped down to the first blank after the last filled cell. Then I tried replacing
("B" & Rows.Count)
with
(ActiveCell & ":" & Rows.Count)
but that got no results at all. I even tried replacing both at once, but that just produced an error message.
So-oo.... sad and confused. But grateful for both your offerings. I'm sure, if I just understood a little more that I could adapt one or the other to get it to do what I need.