View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
leonidas[_64_] leonidas[_64_] is offline
external usenet poster
 
Posts: 1
Default Find and insert?


Hi,

I have a sheet1 with data in column B. I have a sheet2 with also dat
in column B. I have some code below to check if the data from sheet
also exists on sheet1, and if not, then copy it to sheet1.
The only problem is it works 1 time and then I get an error. I am
novice in VBE so that's why the code will look unlogical.
Can someone help me to create a better code that will work? Thanks i
advance!


Code
-------------------
Sub FindAndInsert()

For Each cell In Range("A3:A14")
myvalue = cell.Value
On Error GoTo NextPart
myvalue1 = Sheets("Sheet1").Columns("A:A").Find(What:=myvalue )
GoTo Finalize
NextPart:
cell.Offset(-1, 0).Select
myvalue2 = Selection.Value
Sheets("Sheet1").Select
Columns("A:A").Find(What:=myvalue2).Select
Selection.Offset(1, 0).EntireRow.Insert
Selection.Offset(1, 0).Select
Selection.Value = myvalue
Sheets("Sheet2").Select
Finalize:
Next cell

End Su
-------------------

--
leonida
-----------------------------------------------------------------------
leonidas's Profile: http://www.excelforum.com/member.php...fo&userid=3537
View this thread: http://www.excelforum.com/showthread.php?threadid=56783