We help IT Professionals succeed at work.
Get Started

Copy and Insert/Overwrite

lkirke
lkirke asked
on
868 Views
Last Modified: 2009-11-06
Hi Experts,

Have the following piece of code that I need to adjust.

Basically, the code copy's the named range 'SiteFlows', finds a match to what is in cell A11, then inserts 'SiteFlows' below the match within the range of A61:A65536.

However, if I execute the code twice, it obviously copies the 'SiteFlows' range again below the match and below the already copied data. How can I adjust the code to be a little smarter so that if I have already copied and inserted before, it just copies and overwrites the existing data underneath the match.

I have attached a example for assistance and hoped I haven't confused you too much. :-)
http://s6.quicksharing.com/v/1102894/.html 


Public Sub CopyAndInsert_SiteFlows()

   Dim Row As Long
   
   With ActiveSheet
      Row = Application.Match(.[A11], .[A61:A65536], 0)
      If Row > 0 Then
         .Rows(Row + 61).Resize([SiteFlows].Rows.Count).Insert
         [SiteFlows].EntireRow.Copy .Rows(Row + 61).Resize([SiteFlows].Rows.Count)
        .Rows(Row + 61).Resize([SiteFlows].Rows.Count).Value = .Rows(Row + 61).Resize([SiteFlows].Rows.Count).Value
      End If
   End With

End Sub

Regards

LK
Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2008
Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE