1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Simple Excel Macro to Copy Row from one Sheet to Another

Discussion in 'Business Applications' started by exterminar, Aug 13, 2009.

Thread Status:
Not open for further replies.
  1. exterminar

    exterminar Thread Starter

    Joined:
    Aug 13, 2009
    Messages:
    2
    I'll try to be as descriptive as possible.

    Current Status:
    I have an excel file with two sheets: sheet1 and sheet2.
    Column "A" will have lots of data.
    Some rows in column "A" (or the first cell for that row) will have the word "Directory".

    Intent:
    I need to search sheet2, only in column "A", for the row that contains the word "Directory" and copy that whole row onto sheet1 in the same row. Continue doing that until it completes through all of the rows.

    Example Data:

    (Before)
    sheet2
    Row Column A Column B Column C
    1 blah blah blah blah blah blah
    2 blah blah blah blah blah blah
    3 blah blah blah blah blah blah
    4 Directory cool text huh?????
    5 blah blah blah blah blah blah

    sheet1
    Row Column A
    Row Column A Column B Column C
    1 blah blah blah blah blah blah
    2 blah blah blah blah blah blah
    3 blah blah blah blah blah blah
    4 blah blah blah blah blah blah
    5 blah blah blah blah blah blah

    *Action: Column "A" find "Directory" Copy Row 4 to sheet1

    (After)
    sheet1
    Row Column A
    1 blah blah blah blah blah blah
    2 blah blah blah blah blah blah
    3 blah blah blah blah blah blah
    4 Directory cool text huh?????
    5 blah blah blah blah blah blah
     
  2. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    "copy that whole row onto sheet1 in the same row"

    Do you mean like this?

    (make sure what you already have is "safe" before you try, obviously)

    Sub test()
    If ActiveSheet.Name <> "Sheet2" Then Exit Sub
    LastRow = Range("A" & Rows.Count).End(xlUp).Row
    For Each Cell In Range("A1:A" & LastRow)
    If InStr("Directory", Cell.Value) <> 0 Then
    x = Cell.Row
    Rows(x).Copy
    Sheets("Sheet1").Cells(x, 1).Insert Shift:=xlDown
    End If
    Next Cell
    Application.CutCopyMode = False
    End Sub
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/852112

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice