Variable range

  • Thread starter Thread starter farid2001
  • Start date Start date
F

farid2001

Hello, I need help with code.

I have a macro that I use to process each calling card account's information.

A B C D
etc.
Date Number_dialed Location Duration

all columns have the same number of rows, but this number changes depending
of the amount of calls made from each account.

I have set the fixed range in my macro from 2:3800, but most of the time the
number of raws do'nt exceed 1000

Is there a way to just process the number of raws in each account instead of
going the full 3800?

Your help will be grately apreciated

Regards
 
instead of 3800 do this:
add these 2 lines at the top of the code:

dim ws as worksheet
dim lastrow as long

then add these 2 lines:
set ws = worksheets("Sheet1")
lastrow = ws.Cells(Rows.Count, "A").End(xlUp).Row

then for your range use this:

ws.range("A2:A" & lastrow)

i like to qualify the ranges with the sheet name, i used sheet1, use whatever
your sheet name is.
i used column A in the lastrow statement, use whatever column you are using.
 
RngEnd = Range("A1").End(xlDown).Row
gives the No of the last used row. Use this No in cell references, e.g.
Range("A" & RngEnd) instead of Range("A3800")

Regards,
Stefi

„farid2001†ezt írta:
 
Thank you very much Gary, your code worked very well!!
Regards
farid2001
 
Stefi
Thank you very much, your code worked very well!!

Regards
farid2001
 
You are welcome! Thanks for the feedback!
Stefi

„farid2001†ezt írta:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top