![]() |
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 |
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 |
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 |
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. |
All times are GMT +1. The time now is 02:22 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com