Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Loop Till the end of used Cell

Dear all,

I have following code which loop till the end of a column.
But it is rather slow. I want to
change the code that only loop the column till the last row that have
data entered. I do not want it to loop to Range("A1").End(xlDown).
How can I do that?

For Each cell In ActiveWorkbook.Worksheets("sheet1").Range("A1",
Range("A1").End(xlDown))

If cell.Value = TextBox1.Text Then
cell.Offset(0, 1).Select
Selection.Value = "Yes"
flag = True
Count = Count + 1
TextBox1.Text = ""
Exit Sub
End If
Next cell
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default Loop Till the end of used Cell

I wouldn't use select, that slows your procedure down.

try this:

For Each cell In ActiveWorkbook.Worksheets("sheet1").Range("A1",
Range("A1").End(xlDown))
If cell.Value = TextBox1.Text Then
cell.Offset(0, 1).Value = "Yes"
flag = True
Count = Count + 1
TextBox1.Text = ""
Exit Sub
End If
Next cell

I am not sure what you need flag and count for, but that doesn't
matter that much.

Right now the code would stop at an empty cell, i would do following:
For Each cell In ActiveWorkbook.Worksheets("sheet1").Range("A1",
Range("A65536").End(xlup))
(Pay attention to the wordwrap, above should be on one line!!!)

then you could also add
application.screenupdating = false
(do not forget to reset it to true after the code is finished!!!)

hth Carlo



On Jan 7, 3:31*pm, hon123456 wrote:
Dear all,

* * * * * *I have following code which loop till the end of a column.
But it is rather slow. I want to
change the code that only loop the column till the last row that have
data entered. I do not want it to loop to Range("A1").End(xlDown).
How can I do that?

For Each cell In ActiveWorkbook.Worksheets("sheet1").Range("A1",
Range("A1").End(xlDown))

* * * * * * If cell.Value = TextBox1.Text Then
* * * * * * * * cell.Offset(0, 1).Select
* * * * * * * * Selection.Value = "Yes"
* * * * * * * * flag = True
* * * * * * * * Count = Count + 1
* * * * * * * * TextBox1.Text = ""
* * * * * * * * Exit Sub
* * * * * * End If
* * * * Next cell


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default Loop Till the end of used Cell

With ActiveWorkbook.Worksheets("sheet1")
For Each cell In .Range("A1", .Cells(.Rows.Count, 1).End(xlUp))
If Trim(cell.Value) = Trim(TextBox1.Text) Then
cell.Offset(0, 1).Value = "Yes"
flag = True
Count = Count + 1
TextBox1.Text = ""
Exit Sub
End If
Next cell
End With


--

Regards,
Nigel




"hon123456" wrote in message
...
Dear all,

I have following code which loop till the end of a column.
But it is rather slow. I want to
change the code that only loop the column till the last row that have
data entered. I do not want it to loop to Range("A1").End(xlDown).
How can I do that?

For Each cell In ActiveWorkbook.Worksheets("sheet1").Range("A1",
Range("A1").End(xlDown))

If cell.Value = TextBox1.Text Then
cell.Offset(0, 1).Select
Selection.Value = "Yes"
flag = True
Count = Count + 1
TextBox1.Text = ""
Exit Sub
End If
Next cell


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
Loop till value changes Ruben Excel Discussion (Misc queries) 2 August 27th 08 09:07 AM
Copy cell contents in empty rows below it till any unempty row com vtmalhan Excel Discussion (Misc queries) 1 February 11th 08 11:26 AM
count rows till cell is blank Junior728 Excel Programming 7 April 13th 07 01:14 PM
delete dulipate rows by checking each and every cell in a row till end. sreedhar Excel Programming 4 September 30th 05 11:20 AM
macro to loop till end of page Nadiya Excel Programming 1 November 10th 04 05:18 PM


All times are GMT +1. The time now is 04:42 PM.

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"