PC Review


Reply
Thread Tools Rate Thread

code for counting/shifting

 
 
=?Utf-8?B?Qm9yaXNT?=
Guest
Posts: n/a
 
      22nd Feb 2007
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 With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      22nd Feb 2007
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" <(E-Mail Removed)> wrote in message
news:54738677-5BAE-47BF-8B28-(E-Mail Removed)...
>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 With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      22nd Feb 2007
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 With Quote
 
Don Guillett
Guest
Posts: n/a
 
      22nd Feb 2007
Maybe this will help.
Sub cellstoright()
Set mr = ActiveCell.Resize(1, 10)
For Each c In mr
'If c <> "" Then MsgBox c.Address
If c <> "" Then c.value=c*10
Next c
End Sub


--
Don Guillett
SalesAid Software
(E-Mail Removed)
"BorisS" <(E-Mail Removed)> wrote in message
news:54738677-5BAE-47BF-8B28-(E-Mail Removed)...
>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 With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      22nd Feb 2007
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" <(E-Mail Removed)> wrote in message
> news:54738677-5BAE-47BF-8B28-(E-Mail Removed)...
> >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 With Quote
 
=?Utf-8?B?Qm9yaXNT?=
Guest
Posts: n/a
 
      23rd Feb 2007
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 With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      23rd Feb 2007
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" <(E-Mail Removed)> wrote in message
news:03E782F6-9909-4C9B-8E7A-(E-Mail Removed)...
> 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 With Quote
 
Don Guillett
Guest
Posts: n/a
 
      23rd Feb 2007
Have you tried looking in the vba help index for RESIZE, especially, RESIZE
PROPERTY
--
Don Guillett
SalesAid Software
(E-Mail Removed)
"BorisS" <(E-Mail Removed)> wrote in message
news:03E782F6-9909-4C9B-8E7A-(E-Mail Removed)...
> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple code for shifting =?Utf-8?B?Ti5G?= Microsoft Excel Misc 1 6th Jul 2007 10:38 PM
Counting in Code =?Utf-8?B?UGFjbw==?= Microsoft Access Reports 2 27th Sep 2006 05:11 PM
Counting Lines of Code =?Utf-8?B?TFRvZnNydWQ=?= Microsoft Access Form Coding 8 12th May 2005 08:20 PM
Counting Code Todd Huttenstine Microsoft Excel Programming 4 15th Apr 2004 12:34 PM
Counting names thru code Tom Jameson Microsoft Excel Programming 2 19th Nov 2003 08:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:54 PM.