Creating a range with variable length

Boomdiddygop

New Member
Joined
Oct 3, 2013
Messages
5
Hi, I'm trying to write a code that finds the next empty cell in Column A and then sets that as a range.
Once that is complete, I want to create a For Each loop for that range.

So far what I have is:

Range("A1").Select
ActiveCell.End(xlDown).Select
For Each c In [A2:ActiveCell.Address]
Does actions
Next


I've tried a few ways of labeling the range, but I can't seem to make it run through. I keep getting a type mismatch error.

Any advice would be much appreciated.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Welcome to MrExcel.

Skip the Selecting and try:

Code:
For Each c In Range("A2:A" & Range("A1").End(xlDown).Row)
'    Does actions
Next c
 
Upvote 0
Try this.

Code:
Dim rng As Range
Dim cl As Range

    Set rng = Range("A1", Range("A" & Rows.Count).End(xlUp))

    For Each cl In rng.Cells
        ' Does actions
    Next cl
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,400
Members
449,156
Latest member
LSchleppi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top