for each ActiveSheet.Range problem

Johndd

New Member
Joined
Apr 3, 2014
Messages
6
Hi all,

i have problem with macro:

Dim iCell As Range
count = 1
last = ActiveSheet.Range("a3").End(xlDown).Select
For Each iCell In ActiveSheet.Range("a3", ActiveSheet.Range("a3").End(xlDown)).Select
iCell.Value = count
count = count + 1
Next iCell


Debug problem - "Object reguired" in line "For Each iCell In Ac..."

I need insert increment number from a3 to last ActiveSheet range..

ActiveSheet.Range("a3", ActiveSheet.Range("a3").End(xlDown)).Select is correct. But in foreach i need other syntax?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Dim iCell as Range

With Activesheet
For i = 1 to .Cells(3,1).End(xlDown).Row
.Cells(i,1) = i
Next i
End With
 
Upvote 0
"With Activesheet" is implicit. So you don't need the "With" or the . in front of Cells.

Code:
Dim i As Long
[COLOR=#333333]For i = 1 to Cells(3,1).End(xlDown).Row[/COLOR]
[COLOR=#333333]    Cells(i,1) = i[/COLOR]
[COLOR=#333333]Next i
[/COLOR]


 
Upvote 0
As I look back at the original question, the problem was the ".Select" at the end of the Range.

ActiveSheet.Range("a3", ActiveSheet.Range("a3").End(xlDown)) provides a range object.

ActiveSheet.Range("a3", ActiveSheet.Range("a3").End(xlDown)).Select does something to the Range and doesn't return anything.

 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,843
Members
449,471
Latest member
lachbee

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