Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Excel Macro to insert rows

Hello,

I have a work sheet in thich the parameters are arranged as per the
temp. I have to find the word 'temp 'and insert a complete row before
temp. Can I get some help tp write the excel macro for the same.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Excel Macro to insert rows

Try this one - click any cell in the column where the word "temp" is expected
to be then run the macro. As it is setup it ignores case, so "Temp" = "temp"
etc and it looks for "temp" anywhere in the cells, so "no temp" or "temp."
would be treated as "temp" and a row will be inserted. If 'temp' or the
exact phrase is all that should be in a cell, then change the part of the
..Find commands from
LookAt:=xlPart,
to
LookAt:=xlWhole,

Hope this helps at least a little.

Sub InsertRowAfterTemp()
Dim LastTempRowFound As Long

Selection.EntireColumn.Select
On Error Resume Next
Selection.Find(What:="temp", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
If Err < 0 Then
Err.Clear
MsgBox "Phrase not found in this column."
ActiveCell.Select ' unselect the column
Exit Sub
End If
ActiveCell.Select ' at 1st row with a match
LastTempRowFound = ActiveCell.Row
Selection.EntireRow.Insert
ActiveCell.Offset(1, 0).Select
Application.ScreenUpdating = False ' speed things up
Do Until ActiveCell.Row <= LastTempRowFound
Cells.Find(What:="temp", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Select

Selection.EntireRow.Insert
If ActiveCell.Row LastTempRowFound Then
LastTempRowFound = ActiveCell.Row
End If
ActiveCell.Offset(1, 0).Activate
Loop
Application.ScreenUpdating = True

End Sub




"Dhawal" wrote:

Hello,

I have a work sheet in thich the parameters are arranged as per the
temp. I have to find the word 'temp 'and insert a complete row before
temp. Can I get some help tp write the excel macro for the same.


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7
Default Excel Macro to insert rows

I appreciate it. That absolutely solves my problem.



JLatham (removethis) wrote:
Try this one - click any cell in the column where the word "temp" is expected
to be then run the macro. As it is setup it ignores case, so "Temp" = "temp"
etc and it looks for "temp" anywhere in the cells, so "no temp" or "temp."
would be treated as "temp" and a row will be inserted. If 'temp' or the
exact phrase is all that should be in a cell, then change the part of the
.Find commands from
LookAt:=xlPart,
to
LookAt:=xlWhole,

Hope this helps at least a little.

Sub InsertRowAfterTemp()
Dim LastTempRowFound As Long

Selection.EntireColumn.Select
On Error Resume Next
Selection.Find(What:="temp", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
If Err < 0 Then
Err.Clear
MsgBox "Phrase not found in this column."
ActiveCell.Select ' unselect the column
Exit Sub
End If
ActiveCell.Select ' at 1st row with a match
LastTempRowFound = ActiveCell.Row
Selection.EntireRow.Insert
ActiveCell.Offset(1, 0).Select
Application.ScreenUpdating = False ' speed things up
Do Until ActiveCell.Row <= LastTempRowFound
Cells.Find(What:="temp", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Select

Selection.EntireRow.Insert
If ActiveCell.Row LastTempRowFound Then
LastTempRowFound = ActiveCell.Row
End If
ActiveCell.Offset(1, 0).Activate
Loop
Application.ScreenUpdating = True

End Sub




"Dhawal" wrote:

Hello,

I have a work sheet in thich the parameters are arranged as per the
temp. I have to find the word 'temp 'and insert a complete row before
temp. Can I get some help tp write the excel macro for the same.



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Excel Macro to insert rows

Those are always good words to see. Thanks for letting me know that it was
effective. Glad to have been able to be of assistance.

"Dhawal" wrote:

I appreciate it. That absolutely solves my problem.



JLatham (removethis) wrote:
Try this one - click any cell in the column where the word "temp" is expected
to be then run the macro. As it is setup it ignores case, so "Temp" = "temp"
etc and it looks for "temp" anywhere in the cells, so "no temp" or "temp."
would be treated as "temp" and a row will be inserted. If 'temp' or the
exact phrase is all that should be in a cell, then change the part of the
.Find commands from
LookAt:=xlPart,
to
LookAt:=xlWhole,

Hope this helps at least a little.

Sub InsertRowAfterTemp()
Dim LastTempRowFound As Long

Selection.EntireColumn.Select
On Error Resume Next
Selection.Find(What:="temp", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
If Err < 0 Then
Err.Clear
MsgBox "Phrase not found in this column."
ActiveCell.Select ' unselect the column
Exit Sub
End If
ActiveCell.Select ' at 1st row with a match
LastTempRowFound = ActiveCell.Row
Selection.EntireRow.Insert
ActiveCell.Offset(1, 0).Select
Application.ScreenUpdating = False ' speed things up
Do Until ActiveCell.Row <= LastTempRowFound
Cells.Find(What:="temp", After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Select

Selection.EntireRow.Insert
If ActiveCell.Row LastTempRowFound Then
LastTempRowFound = ActiveCell.Row
End If
ActiveCell.Offset(1, 0).Activate
Loop
Application.ScreenUpdating = True

End Sub




"Dhawal" wrote:

Hello,

I have a work sheet in thich the parameters are arranged as per the
temp. I have to find the word 'temp 'and insert a complete row before
temp. Can I get some help tp write the excel macro for the same.




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
How to stop Excel remembering/loading macro from previously opened Workbook Norman Yuan Excel Discussion (Misc queries) 4 June 17th 06 04:13 PM
excel 4.0 macro removal tool Sachin Shah Excel Discussion (Misc queries) 0 August 25th 05 04:17 AM
Insert rows Mr. G. Excel Worksheet Functions 3 March 31st 05 03:49 AM
Activate a macro to insert a row and copy the formuals from the rows above to the blank row oil_driller Excel Discussion (Misc queries) 1 February 11th 05 03:30 PM
Is there a way to insert a formula, password or macro in an excel spreadsheet that will automatically delete the spreadsheet? oil_driller Excel Discussion (Misc queries) 1 February 8th 05 09:34 AM


All times are GMT +1. The time now is 09:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"