ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Basic Code Problem (https://www.excelbanter.com/excel-programming/335153-basic-code-problem.html)

fugfug[_12_]

Basic Code Problem
 

I have a small problem with one line of code.

Do While ActiveCell.Row < rw


It is part of a loop that works but I need it to use the active cell
from a certain sheet (Carriage). I have tried it as below but it doesnt
work. Think this is just a basic code error but can't work it out.

Do While Sheets("Carriage").ActiveCell.Row < rw

Thanks.

James


--
fugfug
------------------------------------------------------------------------
fugfug's Profile: http://www.excelforum.com/member.php...o&userid=24950
View this thread: http://www.excelforum.com/showthread...hreadid=389017


dominicb[_65_]

Basic Code Problem
 

Good afternoon FugFug

Your code is correct, however the ActiveCell is the currently selected
cell in the currently selected sheet, so you cannot tell Excel to find
the activecell in a diiferent sheet - that is why the error is
returned. You will need to reference the address direct or load it
into a variable and call it that way.

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=389017


Chip Pearson

Basic Code Problem
 
Try something like

Dim Rng As Range
Set Rng = Sheets("Carriage").ActiveCell
While Rng.Row < rw
' do something
Set Rng = Rng(2,1)
Loop


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"fugfug"
wrote in message
...

I have a small problem with one line of code.

Do While ActiveCell.Row < rw


It is part of a loop that works but I need it to use the active
cell
from a certain sheet (Carriage). I have tried it as below but
it doesnt
work. Think this is just a basic code error but can't work it
out.

Do While Sheets("Carriage").ActiveCell.Row < rw

Thanks.

James


--
fugfug
------------------------------------------------------------------------
fugfug's Profile:
http://www.excelforum.com/member.php...o&userid=24950
View this thread:
http://www.excelforum.com/showthread...hreadid=389017




Dave Peterson

Basic Code Problem
 
Maybe...

Sheets("Carriage").select
Do While ActiveCell.Row < rw
....



fugfug wrote:

I have a small problem with one line of code.

Do While ActiveCell.Row < rw

It is part of a loop that works but I need it to use the active cell
from a certain sheet (Carriage). I have tried it as below but it doesnt
work. Think this is just a basic code error but can't work it out.

Do While Sheets("Carriage").ActiveCell.Row < rw

Thanks.

James

--
fugfug
------------------------------------------------------------------------
fugfug's Profile: http://www.excelforum.com/member.php...o&userid=24950
View this thread: http://www.excelforum.com/showthread...hreadid=389017


--

Dave Peterson


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com