+ Reply to Thread
Results 1 to 4 of 4

Allowing for variable lines in macros

  1. #1
    smurrock
    Guest

    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. #2
    Don Guillett
    Guest

    Re: 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
    dguillett1@austin.rr.com
    "smurrock" <smurrock@discussions.microsoft.com> wrote in message
    news:3E5E4733-D3F0-4A0F-88A6-C687298083D5@microsoft.com...
    >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. #3
    Tom Ogilvy
    Guest

    RE: 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. #4
    Gary''s Student
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1