+ Reply to Thread
Results 1 to 3 of 3

Inserting row based on critéria using VBA

  1. #1
    Registered User
    Join Date
    02-06-2006
    Posts
    5

    Inserting row based on critéria using VBA

    HI,

    I would like to insert a row when a certain cell has a certain value. The ideia is to divide the values into weeks, inserting an empty row after every sunday (where I wiil put the totals of the week), and group the whole week in order to see just the week total.

    Can anyone help me doing this in VBA?

  2. #2
    Bob Phillips
    Guest

    Re: Inserting row based on critéria using VBA


    Dim oRow As Range
    For Each oRow In Selection.Rows
    If Weekday(oRow.Cells(1, 1).Value) = 1 Then
    oRow.Offset(1, 0).Insert
    End If
    Next oRow

    --

    HTH

    Bob Phillips

    (remove nothere from the email address if mailing direct)

    "RSantos" <[email protected]> wrote in
    message news:[email protected]...
    >
    > HI,
    >
    > I would like to insert a row when a certain cell has a certain value.
    > The ideia is to divide the values into weeks, inserting an empty row
    > after every sunday (where I wiil put the totals of the week), and group
    > the whole week in order to see just the week total.
    >
    > Can anyone help me doing this in VBA?
    >
    >
    > --
    > RSantos
    > ------------------------------------------------------------------------
    > RSantos's Profile:

    http://www.excelforum.com/member.php...o&userid=31240
    > View this thread: http://www.excelforum.com/showthread...hreadid=516687
    >




  3. #3
    Toppers
    Guest

    =?Utf-8?Q?RE:_Inserting_row_based_on_crit=C3=A9?==?Utf-8?Q?ria_using_VBA?=



    This tests a date in cloumn A to see if is a Sunday and then inserts a row.
    Adjust to suit your needs


    HTH

    Sub InsertRow()
    With Worksheets("Sheet1") ' <=== change as required
    lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
    For r = lastrow To 2 Step -1
    If Weekday(.Cells(r, "A"),2) = 7 Then ' <== change test to suit
    your needs
    .Cells(r, "A").Offset(1, 0).EntireRow.Insert
    End If
    Next r
    End With
    End Sub

    "RSantos" wrote:

    >
    > HI,
    >
    > I would like to insert a row when a certain cell has a certain value.
    > The ideia is to divide the values into weeks, inserting an empty row
    > after every sunday (where I wiil put the totals of the week), and group
    > the whole week in order to see just the week total.
    >
    > Can anyone help me doing this in VBA?
    >
    >
    > --
    > RSantos
    > ------------------------------------------------------------------------
    > RSantos's Profile: http://www.excelforum.com/member.php...o&userid=31240
    > View this thread: http://www.excelforum.com/showthread...hreadid=516687
    >
    >


+ 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