Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to recycle through cells in a selected range

using windows XP; created macro to look at each cell in a one column range.
named range. dim. variables. selected worksheet.selected named range.
created for next cell in seledction. see following
Sheets("Sheet2").Select
Range("I16.I45").Select
For Each cell In Selection
If ActiveCell.Value = False Then
ActiveCell.Offset(0, -2).Value = ActiveCell.Offset(0, -2).Value +
Range("step").Value
End If
Next cell
the offset value is increased until the active cell is not false but the
program does not loop to the next cell in the range. how do i correct?
--
stub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default how to recycle through cells in a selected range

A For Each loop does NOT change what cell is active. As it loops, it sets
the control variable ("cell" in your example code) to each cell in the given
range, but unless you explicitly activate the cell, the ActiveCell remains
what it was prior to the loop. Instead of

ActiveCell.Value

use

Cell.Value

or activate cell:

Cell.Activate


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"stub" wrote in message
...
using windows XP; created macro to look at each cell in a one column
range.
named range. dim. variables. selected worksheet.selected named range.
created for next cell in seledction. see following
Sheets("Sheet2").Select
Range("I16.I45").Select
For Each cell In Selection
If ActiveCell.Value = False Then
ActiveCell.Offset(0, -2).Value = ActiveCell.Offset(0, -2).Value +
Range("step").Value
End If
Next cell
the offset value is increased until the active cell is not false but the
program does not loop to the next cell in the range. how do i correct?
--
stub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default how to recycle through cells in a selected range

just insert:
cell.Activate
after the For statement
--
Gary''s Student - gsnu200760


"stub" wrote:

using windows XP; created macro to look at each cell in a one column range.
named range. dim. variables. selected worksheet.selected named range.
created for next cell in seledction. see following
Sheets("Sheet2").Select
Range("I16.I45").Select
For Each cell In Selection
If ActiveCell.Value = False Then
ActiveCell.Offset(0, -2).Value = ActiveCell.Offset(0, -2).Value +
Range("step").Value
End If
Next cell
the offset value is increased until the active cell is not false but the
program does not loop to the next cell in the range. how do i correct?
--
stub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Step through cells in a selected range CLR Excel Programming 1 November 21st 07 06:07 PM
Step through cells in a selected range CLR Excel Programming 0 November 21st 07 06:01 PM
Set Range Using Selected Cells Paputxi Excel Programming 3 May 2nd 06 06:32 PM
Compare a selected Range with a Named range and select cells that do not exist PCLIVE Excel Programming 1 October 18th 05 07:09 PM
max/min of a selected range of cells Srikanth Ganesan[_2_] Excel Programming 1 September 1st 04 10:31 PM


All times are GMT +1. The time now is 02:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"