ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Inserting row based on critéria using VBA (https://www.excelbanter.com/excel-programming/354429-inserting-row-based-crit%E9ria-using-vba.html)

RSantos

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?


--
RSantos
------------------------------------------------------------------------
RSantos's Profile: http://www.excelforum.com/member.php...o&userid=31240
View this thread: http://www.excelforum.com/showthread...hreadid=516687


Bob Phillips[_6_]

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" wrote in
message ...

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




Toppers

Inserting row based on crité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



davesexcel[_11_]

Inserting row based on critéria using VBA
 

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?


Sub ValSunday()
'
Range("A9").Select

If Selection.Value = "Sunday" Then
'your code here
End If

End Sub




copy and paste this in a normal module,
create a button and assin this macro to it:
once you work on the code and add other code that meets your specs,
you can then paste it into your worksheet change event but thats
another story
work on the macro first


--
davesexcel
------------------------------------------------------------------------
davesexcel's Profile: http://www.excelforum.com/member.php...o&userid=31708
View this thread: http://www.excelforum.com/showthread...hreadid=516687



All times are GMT +1. The time now is 05:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com