Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Find a value, then insert a row below that row and copy the contents to the new row

Hi,
can you please help me out with this one:
I have a sheet where I want to find the value "nn" in column D.
Wherever d contains "nn" I want to insert a new row below this row and
then copy the "nn" row to the new row. I have tried a lot of different
versions for myself in VBA but can not seem to get it to work and don't
understand how to set it up to work.

thx,
Stelllar

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Find a value, then insert a row below that row and copy the contents to the new row

try this sub and check if it is ok
Option Explicit


Public Sub test()
Dim f
With ActiveSheet.Columns("d:d")
Set f = (.Find("nn"))
If Not f Is Nothing Then GoTo line1
GoTo line2
End With
line1:
f.Activate
Dim values As Range
Set values = Range(ActiveCell.End(xlToLeft), ActiveCell.End(xlToRight))
ActiveCell.Offset(1, 0).EntireRow.Insert
values.Copy Destination:=ActiveCell.End(xlToLeft).Offset(1, 0)
line2:
End Sub
=============================================



stelllar wrote in message
oups.com...
Hi,
can you please help me out with this one:
I have a sheet where I want to find the value "nn" in column D.
Wherever d contains "nn" I want to insert a new row below this row and
then copy the "nn" row to the new row. I have tried a lot of different
versions for myself in VBA but can not seem to get it to work and don't
understand how to set it up to work.

thx,
Stelllar



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Find a value, then insert a row below that row and copy the contents to the new row

Hi,
thanks a lot, worked like a charm :-)
The whole line1/line2 thing was a really interesting treat. Have to
remember that one.



R.VENKATARAMAN wrote:
try this sub and check if it is ok
Option Explicit


Public Sub test()
Dim f
With ActiveSheet.Columns("d:d")
Set f = (.Find("nn"))
If Not f Is Nothing Then GoTo line1
GoTo line2
End With
line1:
f.Activate
Dim values As Range
Set values = Range(ActiveCell.End(xlToLeft),

ActiveCell.End(xlToRight))
ActiveCell.Offset(1, 0).EntireRow.Insert
values.Copy Destination:=ActiveCell.End(xlToLeft).Offset(1, 0)
line2:
End Sub
=============================================



stelllar wrote in message
oups.com...
Hi,
can you please help me out with this one:
I have a sheet where I want to find the value "nn" in column D.
Wherever d contains "nn" I want to insert a new row below this row

and
then copy the "nn" row to the new row. I have tried a lot of

different
versions for myself in VBA but can not seem to get it to work and

don't
understand how to set it up to work.

thx,
Stelllar


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Find a value, then insert a row below that row and copy the contents to the new row

You would be best advised not to use line 1/ line 2 things. It is much more
straightforward to use a block if statement. Form your own opinion. Which
is easier to understand?

Option Explicit


Public Sub test()
Dim f As Range

With ActiveSheet.Columns("d:d")
Set f = (.Find("nn"))
End With

If Not f Is Nothing Then
f.EntireRow.Copy
f.Offset(1, 0).EntireRow.Insert
End If

Application.CutCopyMode = False

End Sub



--
Regards,
Tom Ogilvy

"stelllar" wrote in message
oups.com...
Hi,
thanks a lot, worked like a charm :-)
The whole line1/line2 thing was a really interesting treat. Have to
remember that one.



R.VENKATARAMAN wrote:
try this sub and check if it is ok
Option Explicit


Public Sub test()
Dim f
With ActiveSheet.Columns("d:d")
Set f = (.Find("nn"))
If Not f Is Nothing Then GoTo line1
GoTo line2
End With
line1:
f.Activate
Dim values As Range
Set values = Range(ActiveCell.End(xlToLeft),

ActiveCell.End(xlToRight))
ActiveCell.Offset(1, 0).EntireRow.Insert
values.Copy Destination:=ActiveCell.End(xlToLeft).Offset(1, 0)
line2:
End Sub
=============================================



stelllar wrote in message
oups.com...
Hi,
can you please help me out with this one:
I have a sheet where I want to find the value "nn" in column D.
Wherever d contains "nn" I want to insert a new row below this row

and
then copy the "nn" row to the new row. I have tried a lot of

different
versions for myself in VBA but can not seem to get it to work and

don't
understand how to set it up to work.

thx,
Stelllar




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Find a value, then insert a row below that row and copy the contents to the new row

thank you Mr;. ogilvy. your advice is very valuable to me. shall follow in
future


Tom Ogilvy wrote in message
...
You would be best advised not to use line 1/ line 2 things. It is much

more
straightforward to use a block if statement. Form your own opinion.

Which
is easier to understand?

Option Explicit


Public Sub test()
Dim f As Range

With ActiveSheet.Columns("d:d")
Set f = (.Find("nn"))
End With

If Not f Is Nothing Then
f.EntireRow.Copy
f.Offset(1, 0).EntireRow.Insert
End If

Application.CutCopyMode = False

End Sub



--
Regards,
Tom Ogilvy

"stelllar" wrote in message
oups.com...
Hi,
thanks a lot, worked like a charm :-)
The whole line1/line2 thing was a really interesting treat. Have to
remember that one.



R.VENKATARAMAN wrote:
try this sub and check if it is ok
Option Explicit


Public Sub test()
Dim f
With ActiveSheet.Columns("d:d")
Set f = (.Find("nn"))
If Not f Is Nothing Then GoTo line1
GoTo line2
End With
line1:
f.Activate
Dim values As Range
Set values = Range(ActiveCell.End(xlToLeft),

ActiveCell.End(xlToRight))
ActiveCell.Offset(1, 0).EntireRow.Insert
values.Copy Destination:=ActiveCell.End(xlToLeft).Offset(1, 0)
line2:
End Sub
=============================================



stelllar wrote in message
oups.com...
Hi,
can you please help me out with this one:
I have a sheet where I want to find the value "nn" in column D.
Wherever d contains "nn" I want to insert a new row below this row

and
then copy the "nn" row to the new row. I have tried a lot of

different
versions for myself in VBA but can not seem to get it to work and

don't
understand how to set it up to work.

thx,
Stelllar










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
Copy contents of Find (Find and Replace) rob_bob Excel Discussion (Misc queries) 0 March 26th 09 11:01 PM
Paste or insert data before and after cel contents New Expressor Excel Discussion (Misc queries) 4 February 17th 09 07:41 PM
How can I insert the contents of a folder into Excel np Excel Discussion (Misc queries) 3 October 3rd 06 07:05 AM
How to insert the contents of two cells in a footer? Pank Excel Discussion (Misc queries) 4 June 2nd 05 02:32 PM
Insert new row as cell contents change George Excel Discussion (Misc queries) 2 January 26th 05 11:47 AM


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