Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default help with macro

My goal is to add a cell between a name i enter and the total so there is
always a blank row. i have this but it only works if cell a4 is changed.

A B c
1 Customers
1 George
2 Sam
3
4 Total

Private Sub Worksheet_Change(ByVal Target As Range)
Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
If Intersect(Target, Range("A4")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring is changed!
For i = lastrow To 2 Step -1
If InStr(1, Cells(i, "a"), "Total", vbTextCompare) Then
Rows(i).Insert
End If
Next
Application.EnableEvents = True
End If
End Sub

Any help would be appreciated


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default help with macro

You have a solution in general questions. Please don't multi post. Check out
this link

http://www.cpearson.com/excel/newposte.htm
--
HTH...

Jim Thomlinson


"jhyatt" wrote:

My goal is to add a cell between a name i enter and the total so there is
always a blank row. i have this but it only works if cell a4 is changed.

A B c
1 Customers
1 George
2 Sam
3
4 Total

Private Sub Worksheet_Change(ByVal Target As Range)
Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
If Intersect(Target, Range("A4")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring is changed!
For i = lastrow To 2 Step -1
If InStr(1, Cells(i, "a"), "Total", vbTextCompare) Then
Rows(i).Insert
End If
Next
Application.EnableEvents = True
End If
End Sub

Any help would be appreciated


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default help with macro

Private Sub Worksheet_Change(ByVal Target As Range)
Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
If Intersect(Target, Range("A:A")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring is changed!
For i = lastrow To 2 Step -1
If InStr(1, Cells(i, "A"), "Total", vbTextCompare) Then
If Cells(i - 1, "A").Value < "" Then
Rows(i).Insert
Exit For
End If
End If
Next
Application.EnableEvents = True
End If
End Sub




--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"jhyatt" wrote in message
...
My goal is to add a cell between a name i enter and the total so there is
always a blank row. i have this but it only works if cell a4 is changed.

A B c
1 Customers
1 George
2 Sam
3
4 Total

Private Sub Worksheet_Change(ByVal Target As Range)
Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
If Intersect(Target, Range("A4")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring is changed!
For i = lastrow To 2 Step -1
If InStr(1, Cells(i, "a"), "Total", vbTextCompare) Then
Rows(i).Insert
End If
Next
Application.EnableEvents = True
End If
End Sub

Any help would be appreciated




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default help with macro

sorry i thoght i had it in the wrong section

"Jim Thomlinson" wrote:

You have a solution in general questions. Please don't multi post. Check out
this link

http://www.cpearson.com/excel/newposte.htm
--
HTH...

Jim Thomlinson


"jhyatt" wrote:

My goal is to add a cell between a name i enter and the total so there is
always a blank row. i have this but it only works if cell a4 is changed.

A B c
1 Customers
1 George
2 Sam
3
4 Total

Private Sub Worksheet_Change(ByVal Target As Range)
Dim lastrow As Long, i As Long
lastrow = Cells(Rows.Count, "a").End(xlUp).Row
If Intersect(Target, Range("A4")) Is Nothing Then
Exit Sub
Else
'The cell you are monitoring is changed!
For i = lastrow To 2 Step -1
If InStr(1, Cells(i, "a"), "Total", vbTextCompare) Then
Rows(i).Insert
End If
Next
Application.EnableEvents = True
End If
End Sub

Any help would be appreciated


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
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
Macro not showing in Tools/Macro/Macros yet show up when I goto VBA editor [email protected] Excel Programming 2 March 30th 07 07:48 PM
Need syntax for RUNning a Word macro with an argument, called from an Excel macro Steve[_84_] Excel Programming 3 July 6th 06 07:42 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 07:11 AM.

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"