Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

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
Query criteria based on a changing criteria list bwilk77 Excel Discussion (Misc queries) 2 May 27th 09 04:03 PM
Vlookup with 2 different criteria before inserting a value Eqa Excel Discussion (Misc queries) 15 November 29th 07 04:44 PM
inserting a row based on a condition. Gary Excel Worksheet Functions 3 August 18th 06 02:09 PM
Inserting a worksheet based on a template Ron de Bruin Excel Programming 2 May 11th 04 12:11 AM
Inserting rows based on count Mike[_77_] Excel Programming 6 April 20th 04 11:14 PM


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

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"