#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Insert row

I want to use code to insert a row above a row where the first value found
in column D equals "G" I do not want to insert an empty row for each "G"
found.

Perhaps the code is similar to code I am already using where rows are
deleted. Any help is appreciated.
Pat

Private Sub DeleteRows_Click()
Dim X As Long
Dim Y As Long
Y = Range("A65536").End(xlUp).Row
'y= find the last non empty cell in column A
For X = Y To 1 Step -1
'Lcase gets the lower case of the word
If LCase(Cells(X, 1).Value) = "s" Then
Rows(X).Delete

End If
Next X

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Insert row

Dim rng as Range, lastrow as Long
lastrow = cells(rows.count,4).End(xlup).row
set rng = Range("D1")
do while ucase(rng) < "G" and rng.Row <= lastrow
rng = rng.offset(1,0)
Loop
if Ucase(rng.Value) = "G" then
rng.Entirerow.Insert
End if

this will insert a row above the first G found in column D. Is that what
you want?

--
Regards,
Tom Ogilvy

"Pat" wrote in message
...
I want to use code to insert a row above a row where the first value found
in column D equals "G" I do not want to insert an empty row for each "G"
found.

Perhaps the code is similar to code I am already using where rows are
deleted. Any help is appreciated.
Pat

Private Sub DeleteRows_Click()
Dim X As Long
Dim Y As Long
Y = Range("A65536").End(xlUp).Row
'y= find the last non empty cell in column A
For X = Y To 1 Step -1
'Lcase gets the lower case of the word
If LCase(Cells(X, 1).Value) = "s" Then
Rows(X).Delete

End If
Next X

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Insert row

Hi, Tom

I have tried your code but it hangs once the commandbutton is clicked. Excel
has to be closed via Ctl-Alt-Del. What could be happening?
Pat


"Tom Ogilvy" wrote in message
...
Dim rng as Range, lastrow as Long
lastrow = cells(rows.count,4).End(xlup).row
set rng = Range("D1")
do while ucase(rng) < "G" and rng.Row <= lastrow
rng = rng.offset(1,0)
Loop
if Ucase(rng.Value) = "G" then
rng.Entirerow.Insert
End if

this will insert a row above the first G found in column D. Is that what
you want?

--
Regards,
Tom Ogilvy

"Pat" wrote in message
...
I want to use code to insert a row above a row where the first value

found
in column D equals "G" I do not want to insert an empty row for each "G"
found.

Perhaps the code is similar to code I am already using where rows are
deleted. Any help is appreciated.
Pat

Private Sub DeleteRows_Click()
Dim X As Long
Dim Y As Long
Y = Range("A65536").End(xlUp).Row
'y= find the last non empty cell in column A
For X = Y To 1 Step -1
'Lcase gets the lower case of the word
If LCase(Cells(X, 1).Value) = "s" Then
Rows(X).Delete

End If
Next X

End Sub






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
Cannot insert worksheet in exel - not available in insert menu pedro39 Excel Worksheet Functions 1 July 24th 08 12:09 PM
insert row / insert column command buttons fairgreen Excel Worksheet Functions 1 October 29th 07 02:41 PM
How can I insert a date with an icon (calendar) insert Alfredo Mederico[_2_] Excel Discussion (Misc queries) 4 September 21st 07 01:20 AM
Can I auto insert a worksheet when I insert a value in a cell. iainc Excel Worksheet Functions 0 April 27th 06 08:37 AM
Insert Next? Or insert a variable number of records...how? Tom MacKay Excel Discussion (Misc queries) 0 April 20th 06 10:44 PM


All times are GMT +1. The time now is 10:22 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"