How to set range
I want to loop through the range of cells that have data. I know how to do
this with a "hard-coded" range: Set r = Range("L2", "L50") For n = 1 To r.Rows.coutn <my code here Next n My problem is that I may have more (or less) than 50 rows. How can I set r equal to rows 2 through the last row with data (I don't want to perform the code on the first row). Thank you for your help, Judy |
How to set range
For n = 1 To Cells(Rows.Count,"A").End(xlUp).Row
<my code here Next n -- HTH RP (remove nothere from the email address if mailing direct) "Judy Ward" wrote in message ... I want to loop through the range of cells that have data. I know how to do this with a "hard-coded" range: Set r = Range("L2", "L50") For n = 1 To r.Rows.coutn <my code here Next n My problem is that I may have more (or less) than 50 rows. How can I set r equal to rows 2 through the last row with data (I don't want to perform the code on the first row). Thank you for your help, Judy |
How to set range
Change
Set r = Range("L2", "L50") to Set r = Range("L2", Range("L65536").End(xlUp)) -- HTH... Jim Thomlinson "Judy Ward" wrote: I want to loop through the range of cells that have data. I know how to do this with a "hard-coded" range: Set r = Range("L2", "L50") For n = 1 To r.Rows.coutn <my code here Next n My problem is that I may have more (or less) than 50 rows. How can I set r equal to rows 2 through the last row with data (I don't want to perform the code on the first row). Thank you for your help, Judy |
How to set range
Thank you very much, this works for me.
"Jim Thomlinson" wrote: Change Set r = Range("L2", "L50") to Set r = Range("L2", Range("L65536").End(xlUp)) -- HTH... Jim Thomlinson "Judy Ward" wrote: I want to loop through the range of cells that have data. I know how to do this with a "hard-coded" range: Set r = Range("L2", "L50") For n = 1 To r.Rows.coutn <my code here Next n My problem is that I may have more (or less) than 50 rows. How can I set r equal to rows 2 through the last row with data (I don't want to perform the code on the first row). Thank you for your help, Judy |
How to set range
For r = 2 to Cells(Rows.Count,"L").End(xlUp)Row
your code Next r -- HTH RP (remove nothere from the email address if mailing direct) "Judy Ward" wrote in message ... I want to loop through the range of cells that have data. I know how to do this with a "hard-coded" range: Set r = Range("L2", "L50") For n = 1 To r.Rows.coutn <my code here Next n My problem is that I may have more (or less) than 50 rows. How can I set r equal to rows 2 through the last row with data (I don't want to perform the code on the first row). Thank you for your help, Judy |
All times are GMT +1. The time now is 11:31 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com