Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default code for counting/shifting

I need some code to do the following:

1) start with a given cell
2) count how many of the 10 cells to the right of it are filled with data
3) for each of those cells, perform a small procedure

My hangup right now is how to get the loop structured, as I always screw up
the definitions of variables, as well as how to use them in code. So if
anyone can give me the first part of this, I can fill in the procedure
inbetween the loop beginning and ending arguments.

Thx.
--
Boris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default code for counting/shifting

With Activecell
For i = 1 To 10
If .Offset(0,1).Value < "" Then
'call procedure
End If
Next i
End With

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"BorisS" wrote in message
...
I need some code to do the following:

1) start with a given cell
2) count how many of the 10 cells to the right of it are filled with data
3) for each of those cells, perform a small procedure

My hangup right now is how to get the loop structured, as I always screw
up
the definitions of variables, as well as how to use them in code. So if
anyone can give me the first part of this, I can fill in the procedure
inbetween the loop beginning and ending arguments.

Thx.
--
Boris



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default code for counting/shifting

Dim rng as Range, cell as Range, cnt as Long
set rng = activecell.offset(0,1).Resize(1,10)
cnt = application.countA(rng)
for each cell in rng
if len(trim(cell.value)) 0 then
cell.Select
myprocedure
end if
Next

--
Regards,
Tom Ogilvy


Assumes your procedure acts on the active cell. or just write your code to
work with the range reference: cell (and skip the select command)

--
Regards,
Tom Ogilvy


"BorisS" wrote:

I need some code to do the following:

1) start with a given cell
2) count how many of the 10 cells to the right of it are filled with data
3) for each of those cells, perform a small procedure

My hangup right now is how to get the loop structured, as I always screw up
the definitions of variables, as well as how to use them in code. So if
anyone can give me the first part of this, I can fill in the procedure
inbetween the loop beginning and ending arguments.

Thx.
--
Boris

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default code for counting/shifting

typo:

With Activecell
For i = 1 To 10
If .Offset(0,i).Value < "" Then '<== change here
'call procedure
End If
Next i
End With


"Bob Phillips" wrote:

With Activecell
For i = 1 To 10
If .Offset(0,1).Value < "" Then
'call procedure
End If
Next i
End With

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"BorisS" wrote in message
...
I need some code to do the following:

1) start with a given cell
2) count how many of the 10 cells to the right of it are filled with data
3) for each of those cells, perform a small procedure

My hangup right now is how to get the loop structured, as I always screw
up
the definitions of variables, as well as how to use them in code. So if
anyone can give me the first part of this, I can fill in the procedure
inbetween the loop beginning and ending arguments.

Thx.
--
Boris






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default code for counting/shifting

what does the resize part do, just for my education?

Thx for the help to all.
--
Boris


"Tom Ogilvy" wrote:

Dim rng as Range, cell as Range, cnt as Long
set rng = activecell.offset(0,1).Resize(1,10)
cnt = application.countA(rng)
for each cell in rng
if len(trim(cell.value)) 0 then
cell.Select
myprocedure
end if
Next

--
Regards,
Tom Ogilvy


Assumes your procedure acts on the active cell. or just write your code to
work with the range reference: cell (and skip the select command)

--
Regards,
Tom Ogilvy


"BorisS" wrote:

I need some code to do the following:

1) start with a given cell
2) count how many of the 10 cells to the right of it are filled with data
3) for each of those cells, perform a small procedure

My hangup right now is how to get the loop structured, as I always screw up
the definitions of variables, as well as how to use them in code. So if
anyone can give me the first part of this, I can fill in the procedure
inbetween the loop beginning and ending arguments.

Thx.
--
Boris

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default code for counting/shifting

It resizes the range object to that number of rows and columns.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"BorisS" wrote in message
...
what does the resize part do, just for my education?

Thx for the help to all.
--
Boris


"Tom Ogilvy" wrote:

Dim rng as Range, cell as Range, cnt as Long
set rng = activecell.offset(0,1).Resize(1,10)
cnt = application.countA(rng)
for each cell in rng
if len(trim(cell.value)) 0 then
cell.Select
myprocedure
end if
Next

--
Regards,
Tom Ogilvy


Assumes your procedure acts on the active cell. or just write your code
to
work with the range reference: cell (and skip the select command)

--
Regards,
Tom Ogilvy


"BorisS" wrote:

I need some code to do the following:

1) start with a given cell
2) count how many of the 10 cells to the right of it are filled with
data
3) for each of those cells, perform a small procedure

My hangup right now is how to get the loop structured, as I always
screw up
the definitions of variables, as well as how to use them in code. So
if
anyone can give me the first part of this, I can fill in the procedure
inbetween the loop beginning and ending arguments.

Thx.
--
Boris



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
Code for counting the order cells are filled NDBC Excel Discussion (Misc queries) 1 July 23rd 09 07:26 AM
Simple code for shifting N.F[_2_] Excel Discussion (Misc queries) 1 July 6th 07 10:38 PM
Counting entries by color code Carmen Excel Discussion (Misc queries) 3 September 19th 05 09:45 PM
Counting Code Todd Huttenstine Excel Programming 4 April 15th 04 12:34 PM
Counting names thru code Tom Jameson Excel Programming 2 November 19th 03 08:13 PM


All times are GMT +1. The time now is 06:29 AM.

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

About Us

"It's about Microsoft Excel"