+ Reply to Thread
Results 1 to 4 of 4

Copy range of cells from one sheet to another

  1. #1
    Registered User
    Join Date
    01-16-2015
    Location
    St Louis
    MS-Off Ver
    10
    Posts
    9

    Copy range of cells from one sheet to another

    Using Microsoft Office Professional Plus 2010

    I am working with a macro that looks to see which rows of data contain "Yes" in column F and then it copes those rows to a new sheet. Everything works fine, except I would like to change it to only copy the data in columns A through N and not the entire row. Reason being I would like it to ignore column M on the new sheet.

    This is what I am using;

    Sub Search_For_String()


    Dim LSearchRow As Integer
    Dim LCopyToRow As Integer

    On Error GoTo Err_Execute

    Sheets("Data").Select

    'Start search in row 2
    LSearchRow = 2

    'Start copying data to row 8 in Investigations (row counter variable)
    LCopyToRow = 8

    While Len(Range("A" & CStr(LSearchRow)).Value) > 0

    'If value in column F = "Yes", copy entire row to Investigations
    If Range("F" & CStr(LSearchRow)).Value = "Yes" Then

    'Select row in Data to copy
    Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
    Selection.Copy

    'Paste row into Investigations in next row
    Sheets("Investigations").Select
    Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
    ActiveSheet.Paste

    'Move counter to next row
    LCopyToRow = LCopyToRow + 1

    'Go back to Data to continue searching
    Sheets("Data").Select

    End If

    LSearchRow = LSearchRow + 1

    Wend

    'Position on cell A3
    Application.CutCopyMode = False
    Range("A3").Select

    Sheets("Investigations").Select

    MsgBox "All matching data has been copied."



    Exit Sub

    Err_Execute:
    MsgBox "An error occurred."

    End Sub

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Copy range of cells from one sheet to another

    Try:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    01-16-2015
    Location
    St Louis
    MS-Off Ver
    10
    Posts
    9

    Re: Copy range of cells from one sheet to another

    I am getting an error. It might be because of which sheet is active? I am starting on the "Investigations" sheet via a control button that runs the macro. It is supposed to go back to "data" sheet and grab the data and return back to "Investigations" sheet and paste it there.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Copy range of cells from one sheet to another

    Try:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy range of cells from one sheet to another
    By bdrilling33 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-16-2014, 10:11 PM
  2. Creating a copy button to copy range of cells to a different sheet
    By 5degrees in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-15-2013, 12:21 PM
  3. [SOLVED] Copy noncontiguous range of cells to another sheet
    By Pavan Renjal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-29-2012, 07:57 AM
  4. Replies: 8
    Last Post: 10-23-2011, 01:28 PM
  5. code to copy a range of cells to another sheet
    By Robb27 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-04-2006, 06:30 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1