Results 1 to 6 of 6

Moving rows based on cell value, based against a reference column.

Threaded View

  1. #1
    Registered User
    Join Date
    05-09-2022
    Location
    England
    MS-Off Ver
    365
    Posts
    3

    Moving rows based on cell value, based against a reference column.

    I have a procedure that moves a row based on a cell value.
    This is hard coded into the procedure i.e. if a cell in column A matches "MW" move the row to worksheet "MW"
    I must manually update / duplicate the procedures to add additional options.

    Sub Procedure1()
    Dim c As Range
    Dim LastRow As Long
    LastRow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
        For Each c In ActiveSheet.Range("A2", "A" & LastRow)
            If c.Value = "MW" Then
                c.Offset(0, 0).Select
                    Selection.Resize(Selection.Rows.Count, Selection.Columns.Count + 5).Copy _
                        Destination:=Worksheets("MW").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
            End If
        Next c
    End Sub
    I would like this to be more dynamic so it can check against a reference column and then move the rows accordingly.

    If the cell has a value that matched any in the reference (Column U), it would then move the row to the matching worksheet.

    i.e. if it matches "MW" in the reference column (Column U) it moves to the "MW" worksheet, if it matches "SW" in the reference table (Column U) it moves it to the "SW" worksheet etc.
    This way all I need to do is keep the reference column up to date and keep a single procedure in VBA that does not need to be changed.
    I already have code to create the worksheets based on unique values so please assume there will be a worksheet available to move to.

    Thanks
    Attached Files Attached Files
    Last edited by MatthewWardlow; 05-10-2022 at 04:15 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Moving rows to a new sheet based on the last two digits of variables in a column
    By micaelamorgan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-09-2016, 10:46 PM
  2. Moving Rows into a different sheet based on a cell value
    By ajvalles1 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-02-2015, 08:10 AM
  3. Moving rows to columns based on information in a specific column
    By adamdpayne in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-02-2014, 10:49 AM
  4. [SOLVED] Moving Rows to new Tab based on many possible Cell Values
    By mmanning in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-23-2014, 06:09 AM
  5. Moving Rows From Main doc based on word in column
    By Greggatm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2013, 08:43 PM
  6. moving rows of cells into new column based on conditions
    By myjebay1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-15-2012, 04:36 PM
  7. Replies: 0
    Last Post: 11-11-2005, 02:35 PM

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