Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Allowing for variable lines in macros

I am trying to set up a macro to run for a data file that will not have a
consistent number of lines each month. This seems like it should be simple,
however I am struggling. I tried using relative references but either I
didn't set it up right or it won't work. I also tried using offset which
also failed. This seems pretty basic??

Thanks!!
Sidonia
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Allowing for variable lines in macros

You didn't post your code so see if this idea helps to find the last row in
col A

lastrow=cells(rows.count,"a").end(xlup).row

--
Don Guillett
SalesAid Software

"smurrock" wrote in message
...
I am trying to set up a macro to run for a data file that will not have a
consistent number of lines each month. This seems like it should be
simple,
however I am struggling. I tried using relative references but either I
didn't set it up right or it won't work. I also tried using offset which
also failed. This seems pretty basic??

Thanks!!
Sidonia



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Allowing for variable lines in macros

Basic approach:

Dim rng as Range, cell as Range
With ActiveWorkbook.worksheets(1)
set rng = .range(.cells(1,1),.cells(rows.count,1).End(xlup))
End With

for each cell in rng


Next

--
Regards,
Tom Ogilvy


"smurrock" wrote:

I am trying to set up a macro to run for a data file that will not have a
consistent number of lines each month. This seems like it should be simple,
however I am struggling. I tried using relative references but either I
didn't set it up right or it won't work. I also tried using offset which
also failed. This seems pretty basic??

Thanks!!
Sidonia

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Allowing for variable lines in macros

Try using ActiveSheet.UsedRange. It should reflect the rows in your current
data:

Set r = ActiveSheet.UsedRange

nLastRow = r.Rows.Count + r.Row - 1
MsgBox ("last row " & nLastRow)

nLastColumn = r.Columns.Count + r.Column - 1
MsgBox ("last column " & nLastColumn)

nFirstRow = r.Row
MsgBox ("first row " & nFirstRow)

nFirstColumn = r.Column
MsgBox ("first column " & nFirstColumn)

numrow = r.Rows.Count
MsgBox ("number of rows " & numrow)

numcol = r.Columns.Count
MsgBox ("number of columns " & numcol)


etc.
--
Gary''s Student


"smurrock" wrote:

I am trying to set up a macro to run for a data file that will not have a
consistent number of lines each month. This seems like it should be simple,
however I am struggling. I tried using relative references but either I
didn't set it up right or it won't work. I also tried using offset which
also failed. This seems pretty basic??

Thanks!!
Sidonia

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
30-yr Amortization allowing 26 payments per year/780 lines vs 360 vbpatton Excel Worksheet Functions 1 May 6th 06 02:43 PM
How can I lock worksheets while still allowing macros to operate? enginguven Excel Discussion (Misc queries) 2 January 9th 06 10:06 PM
How can I lock worksheets while still allowing macros to operate? enginguven Excel Discussion (Misc queries) 1 January 9th 06 09:47 PM
Allowing for variable cell reference in macro tx12345 Excel Worksheet Functions 2 December 24th 05 04:50 AM
Allowing Macros in Excel Trevor Setting up and Configuration of Excel 1 February 18th 05 10:48 PM


All times are GMT +1. The time now is 08:54 AM.

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"