MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 30th, 2004, 02:23 AM   #1
UALynn
 
Join Date: Mar 2004
Posts: 15
Default find next used cell

Awright, I'm just getting frustrated here.

I want to start in cell A1 and working my way down the column locate the next used cell.

So if cells A3, A7, and A98 have data my psuedo code would be like



The data looks like
Col A ColB
Test
data
data

Another
more
more
more

And
more again

sorry the post didn't space things as expected

I know how to use offset.
I have tried using .end(xldown) to get to the next data point in column A, but I keep getting unexpected results.
UALynn is offline   Reply With Quote
Old Mar 30th, 2004, 02:48 AM   #2
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,738
Default Re: find next used cell

Try using SpecialCells

Dim Rng As Range

Set Rng = Range("A:A").SpecialCells(xlCellTypeConstants)

or more specific

Set Rng = Range("A:A").SpecialCells(xlCellTypeConstants,xlTextValues)
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old Mar 30th, 2004, 04:41 PM   #3
UALynn
 
Join Date: Mar 2004
Posts: 15
Default Re: find next used cell

Thanks, not quite the effect I wanted, but still good to know.
UALynn is offline   Reply With Quote
Old Mar 30th, 2004, 05:54 PM   #4
NateO
MrExcel MVP
Admin
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,617
Default Re: find next used cell

If your data looks like:

Code:
ColA ColB
GroupA (Empty)
(Empty) Member1
(Empty) Member2
GroupB (Empty)
(Empty) Member2
(Empty) Member3
Use an autofilter on A and B for non-blanks. Then loop through the visible cells. I.e.,

Set Rng = Range("A:A").SpecialCells(xlvisible)

__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Nate's Excel Blog
NateO is offline   Reply With Quote
Old Mar 30th, 2004, 06:01 PM   #5
UALynn
 
Join Date: Mar 2004
Posts: 15
Default Re: find next used cell

I ended up with looping through all the cells in A and B
If A is empty go looking for B and hang on to the last known A value. Do this until B is empty. Then go back and look for the next A and do it all over again.

Works. Ain't pretty, but it works.
UALynn is offline   Reply With Quote
Old Mar 30th, 2004, 06:07 PM   #6
NateO
MrExcel MVP
Admin
 
NateO's Avatar
 
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,617
Default Re: find next used cell

I still vote for an autofilter. E.g.,

http://www.mrexcel.com/board2/viewto...=77261&start=8

These are easy, turn on your macro recorder for the syntax.

__________________
Regards,
Nate Oliver
Microsoft Excel MVP
Nate's Excel Blog
NateO is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 04:32 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.