View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Find and insert?

I'm assuming you have a header row that is the same (cell A2)....


Sub FindAndInsertVer2()
Dim cell As Range
Dim myCell As Range

For Each cell In Sheets("Sheet2").Range("A3:A14")
If IsError(Application.Match(cell.Value, _
Worksheets("Sheet1").Range("A:A"), False)) Then
Set myCell = Worksheets("Sheet1").Range("A:A").Find(cell(0, 1).Value)
myCell(2, 1).EntireRow.Insert
cell.Copy myCell(2, 1)
End If
Next cell
End Sub

HTH,
Bernie
MS Excel MVP


"leonidas" wrote in message
...

Hi Bernie,

Sorry, I think I haven't explained the situation enough.
Sheet2 is a copy of sheet1 (this is to track changes afterwards and
sheet1 cannot be changed after making the copy (protected)). Sheet2 has
also another user than sheet1. The user of sheet2 can delete and insert
rows in column A (only on specific rows, the rest is protected). When
the user of sheet2 is ready, a resume is made on a new sheet.
The data of sheet1 is copied to this new sheet, but because the user of
sheet2 has made some changes, these changes should also be visible in
the resume. Deleting data in sheet2 is no problem, because the original
data is in sheet1. But inserting is a problem. These inserted data
should be copied to the resume.
For example:
If sheet1 has data:
a (protected)
b
c
d (protected)
e
f
g
h
and the user of sheet2 changes this to:
a (protected)
c
d (protected)
x
y
z
e
f
g
h
it should be possible to allways copy the new data to the right place
when checking the data a row above like in the code below. Only this
code doesn't work.
Could you please help me fix the code. Thanks again!


Code:
--------------------
Sub FindAndInsertOK()
Dim cell As Range

For Each cell In Sheets("Sheet2").Range("A3:A14")
myvalue = cell.Value
If IsError(Application.Match(myvalue, _
Worksheets("Sheet1").Range("A:A"), False)) Then
cell.Offset(-1, 0).Select
myvalue1 = Selection.Value
Sheets("Sheet1").Select
Columns("A:A").Find(What:=myvalue1).Select
Selection.Offset(1, 0).EntireRow.Insert
Selection.Offset(1, 0).Select
Selection.Value = myvalue
End If
Next cell

End Sub
--------------------


--
leonidas
------------------------------------------------------------------------
leonidas's Profile: http://www.excelforum.com/member.php...o&userid=35375
View this thread: http://www.excelforum.com/showthread...hreadid=567838