+ Reply to Thread
Results 1 to 4 of 4

Make a macro run on rows/columns only if data is present?

  1. #1
    bpreas - ExcelForums.com
    Guest

    Make a macro run on rows/columns only if data is present?

    How can I mave a macro run on fields where there is data present and
    ignore empty rows or columns. I have macros that I use regularly, but
    the number of rows of data in these spreadsheets varies each time.
    Thanks in advance for any help you can provide!


  2. #2
    STEVE BELL
    Guest

    Re: Make a macro run on rows/columns only if data is present?

    You can build If .... Then....Else....End IF statements that check the cells
    Dim cel as range

    If len(cel)>0 then
    ' cell is not blank
    ' do something
    End if

    If cel = 0 then
    ' cell has no value except 0
    ' don't do anything
    Else
    'do something
    End if

    And you can put one or more of those statements into a For .. Next loop

    For each cel in Range("A1:Z55") ''' change the range to suit your needs
    ' your code
    Next

    There are other ways of restricting the ranges that make it even easier.
    But we need to know more about what you really have and what you really are
    looking at...

    --
    steveB

    Remove "AYN" from email to respond
    "bpreas - ExcelForums.com" <[email protected]> wrote in
    message news:%[email protected]...
    > How can I mave a macro run on fields where there is data present and
    > ignore empty rows or columns. I have macros that I use regularly, but
    > the number of rows of data in these spreadsheets varies each time.
    > Thanks in advance for any help you can provide!
    >




  3. #3
    bpreas - ExcelForums.com
    Guest

    Re: Make a macro run on rows/columns only if data is present

    What I have is a macro that inserts a column and fills the cells in
    that column with certain text. I only need the cells filled down to
    the row where the existing data in the adjacent column ends.


  4. #4
    STEVE BELL
    Guest

    Re: Make a macro run on rows/columns only if data is present

    This snippet looks at column A and finds the last used cell (even if there
    are some empty cells in the column) You should be able to make this code
    fit your needs.

    Dim lrw As Integer

    lrw= Cells(Rows.COUNT, "A").End(xlUp).Row

    This one counts the number of used cells in column A (good if there are no
    empty cells)
    lrw = WorksheetFunction.Counta(Columns(1))

    in either case the fill range could be written as
    Set FRange = Sheets("Sheet1").Range("B1:B" & lrw)

    --
    steveB

    Remove "AYN" from email to respond
    "bpreas - ExcelForums.com" <[email protected]> wrote in
    message news:[email protected]...
    > What I have is a macro that inserts a column and fills the cells in
    > that column with certain text. I only need the cells filled down to
    > the row where the existing data in the adjacent column ends.
    >




+ 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