Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default looping thru the worksheet

I was using the ActiveCell.Offset(0, 1).Activate to loop thru my columns to
get the value of the cell

I understand that activating the cell is not needed and it slows thing down

I'm just kind of lost :-) on how I should do this without activating the
cell

What i am attemping to do is start at a certain row then read all the cols.
and then go to next row
comapare to see if they are the same or not... delete if they are and write
a little text file to list what got
blown out ...then go to the row below my first check and do it all over
again

I got my col count and can go across. then I offset back then down a row

this is a one shot that I have been using... should I just compare the whole
row and loop from there...thx

Open wrfile For Append As #1

For q = 1 To colct
ActiveCell.Offset(0, 1).Activate
tval(q) = ActiveCell.Value
If tval(q) = cval(q) Then ' see if values the same
ck(q) = 1 'same value
Else
ck(q) = 0 ' not the same
End If
Next q

ActiveCell.Offset(0, -(colct)).Activate 'return to start col

For q = 1 To colct ' add up check values
ckval = ckval + ck(q)
Next q

If ckval = colct Then ' delete if all ones pass if not

Print #1, ck_name & " replaced " & ActiveCell.Value

Worksheets("Sheet1").Rows(ActiveCell.Row).Delete
Else
ActiveCell.Offset(1, 0).Activate ' move down a row
End If
ckval = 0
TextBox1.Text = ActiveCell.Value
Close


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default looping thru the worksheet

As an example

For q = 1 To colct
ActiveCell.Offset(0, 1).Activate
tval(q) = ActiveCell.Value
If tval(q) = cval(q) Then ' see if values the same
ck(q) = 1 'same value
Else
ck(q) = 0 ' not the same
End If
Next q


could become

For q = 1 To colct
tval(q) = ActiveCell.Offset(0,q).Value
If tval(q) = cval(q) Then ' see if values the same
ck(q) = 1 'same value
Else
ck(q) = 0 ' not the same
End If
Next q

in other words, you are just addressing a cell so many columns offset from
the activecell,. not literally activating them and using the activecell

--

HTH

RP
(remove nothere from the email address if mailing direct)


"cadcamguy" wrote in message
...
I was using the ActiveCell.Offset(0, 1).Activate to loop thru my columns

to
get the value of the cell

I understand that activating the cell is not needed and it slows thing

down

I'm just kind of lost :-) on how I should do this without activating the
cell

What i am attemping to do is start at a certain row then read all the

cols.
and then go to next row
comapare to see if they are the same or not... delete if they are and

write
a little text file to list what got
blown out ...then go to the row below my first check and do it all over
again

I got my col count and can go across. then I offset back then down a row

this is a one shot that I have been using... should I just compare the

whole
row and loop from there...thx

Open wrfile For Append As #1

For q = 1 To colct
ActiveCell.Offset(0, 1).Activate
tval(q) = ActiveCell.Value
If tval(q) = cval(q) Then ' see if values the same
ck(q) = 1 'same value
Else
ck(q) = 0 ' not the same
End If
Next q

ActiveCell.Offset(0, -(colct)).Activate 'return to start col

For q = 1 To colct ' add up check values
ckval = ckval + ck(q)
Next q

If ckval = colct Then ' delete if all ones pass if not

Print #1, ck_name & " replaced " & ActiveCell.Value

Worksheets("Sheet1").Rows(ActiveCell.Row).Delete
Else
ActiveCell.Offset(1, 0).Activate ' move down a row
End If
ckval = 0
TextBox1.Text = ActiveCell.Value
Close




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default looping thru the worksheet

I think I am following your saying with that .....it's a relative offset
from the activecell

so I could take this and turn it into a function so that will shoot me
across the columns

For q = 1 To colct
tval(q) = ActiveCell.Offset(0,q).Value
If tval(q) = cval(q) Then ' see if values the same
ck(q) = 1 'same value
Else
ck(q) = 0 ' not the same
End If
Next q

Then since I want to then loop down the rows checking to the last then
returning to the next row from the initial one
just put a counter in row motion loop that returns me 1 more each time from
inital start row
I think this is making sense since I only have to count up each time it
runs down and have a activecell.offset(ct,0) and a
do until that value is nil to break it out

I'll give it a try :-) ... Thanks again Bob


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default looping thru the worksheet


"cadcamguy" wrote in message
...
I think I am following your saying with that .....it's a relative offset
from the activecell


Or any fixed cell.

so I could take this and turn it into a function so that will shoot me
across the columns

For q = 1 To colct
tval(q) = ActiveCell.Offset(0,q).Value
If tval(q) = cval(q) Then ' see if values the same
ck(q) = 1 'same value
Else
ck(q) = 0 ' not the same
End If
Next q


If making a function, flex it

Function myFunc (rng as Range)
For q = 1 To colct
tval(q) = rng.Offset(0,q).Value
If tval(q) = cval(q) Then ' see if values the same
ck(q) = 1 'same value
Else
ck(q) = 0 ' not the same
End If
Next q
End Function

and call like myFunc(ActiveCell)

so as to make it useable from other cells, not just Activecell

Then since I want to then loop down the rows checking to the last then
returning to the next row from the initial one
just put a counter in row motion loop that returns me 1 more each time

from
inital start row
I think this is making sense since I only have to count up each time it
runs down and have a activecell.offset(ct,0) and a
do until that value is nil to break it out



Don't forget the technique works down or across, just use a different part
of the offset as offset has a RowOffset parameter and a ColOffset parameter.


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
Looping Through Worksheet lark[_2_] Excel Programming 0 May 12th 05 04:37 PM
Only works on One Worksheet, When Looping thru All WS Dean[_5_] Excel Programming 2 January 28th 05 05:41 PM
Looping through charts in a worksheet Grant Excel Programming 1 August 6th 04 09:22 AM
Looping through ComboBoxes in a worksheet TonyM Excel Programming 2 May 18th 04 01:48 PM
Looping checkboxes embedded in worksheet Theresa[_5_] Excel Programming 1 February 27th 04 04:41 AM


All times are GMT +1. The time now is 03:10 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"