+ Reply to Thread
Results 1 to 3 of 3

VBA: copy row from one sheet to another using a specific cell as reference

Hybrid View

  1. #1
    Registered User
    Join Date
    01-08-2018
    Location
    Malaysia
    MS-Off Ver
    MS office 2013
    Posts
    1

    VBA: copy row from one sheet to another using a specific cell as reference

    Hi everyone,

    I am having a problem with my formula below. I am trying to pull out specific rows based on cell reference "B7" in the "Documentation" sheet from the "control matrix' sheet:


    Sub MoveRowBasedOnCellValue()
    
        Dim xRg As Range
        Dim xCell As Range
        Dim I As Long
        Dim J As Long
        Dim K As Long
        I = Worksheets("Control matrix").UsedRange.Rows.Count
        J = Worksheets("Documentation").UsedRange.Rows.Count
        If J = 1 Then
        If Application.WorksheetFunction.CountA(Worksheets("Documentation").UsedRange) = 0 Then J = 0
        End If
        Set xRg = Worksheets("Control matrix").Range("A1:S203" & I)
        On Error Resume Next
        Application.ScreenUpdating = False
        For K = 1 To xRg.Count
            If CStr(xRg(A).Value) = "B7" Then
                xRg(K).EntireRow.Copy Destination:=Worksheets("Documentation").Range("A19" & J + 1)
                J = J + 1
            End If
        Next
    Brief description of data acronyms:
    Control matrix: Is the sheet where the table is in. I want to pull specific rows from this sheet into the Documentation sheet using the cell reference B7
    Documentation: Is the destination path of the rows selected based on cell reference B7.
    A1:S203: Is the excel reference of the table under the control matrix sheet
    B7: Is the cell reference that consist the details that i want to pull out. This cell reference corresponds the details located in column A in the control matrix sheet
    A19: Is the cell that represents the destination where i want the rows to populate into.

    I am really new to this and appreciate all the help I can get to get my formula working. I have attached the workbook as reference.

    Thanks everyone!!

    Regards,

    Shankar
    Attached Files Attached Files
    Last edited by vimalashankar; 01-09-2018 at 03:31 AM.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: VBA: copy row from one sheet to another using a specific cell as reference

    Hi Shankar

    Welcome to the Forum.

    1. In future please view the forum rules before posting. Your post does not comply with rule #3.
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the [#] button at the top of the post window.
    Please correct above by editing post , highlighting code and pressing #

    2. Unfortunately screenshots and word doc's are of no use...
    Attach a sample workbook . Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.
    To attach a file, click on Go Advanced (below the Edit Window) while you are composing a reply, then scroll down to and click on Manage Attachments and the Upload window will open. Click on Browse and navigate to (and double-click) the file icon that you want to attach, then click on Upload and then on Close this Window to return to the Edit window. When you have finished composing your post, click on Submit Post.
    Last edited by Sintek; 01-09-2018 at 02:14 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: VBA: copy row from one sheet to another using a specific cell as reference

    Thank you...
    Is this what you want to achieve...
    Option Explicit
    
    Sub Shankar()
    Dim Process As String
    Process = Sheet2.Range("B7")
    With Sheet4.Cells(1).CurrentRegion
        .AutoFilter 1, Process
        .SpecialCells(12).Copy Sheet2.Range("A19")
    End With
    Sheet4.AutoFilterMode = False
    End Sub

+ 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 specific cell value on sheet1 to specific cell on sheet2 or other sheet.
    By Mr.GfCs in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-20-2015, 02:41 PM
  2. Replies: 2
    Last Post: 11-18-2013, 07:31 AM
  3. [SOLVED] Copy specific cells from 1 sheet to another, conditional upon entering a unique reference.
    By Terri H in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-09-2013, 05:39 AM
  4. Replies: 2
    Last Post: 07-24-2012, 05:58 PM
  5. Copy & paste specific column based on cell reference
    By ccsmith in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2011, 03:59 AM
  6. Search sheet for specific cell and obtain reference
    By sonikin in forum Excel General
    Replies: 5
    Last Post: 05-22-2011, 08:03 PM
  7. Copy specific columns to specific cell on new sheet
    By jones_net in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2010, 02:34 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