Moving select data from one column to a new sheet

KarenKFL

New Member
Joined
Mar 17, 2014
Messages
20
Hi, I have a VBA that works perfect moving selected data from column A to a new sheet. I want to use this VBA in a new workbook, but the data I want is in column X and I can't figure out how to change it to X. So in the source sheet(BRO_20190910) if column X contains the word ECO, I want to move the whole row to the destination sheet(ECO).
This is the original code, thank you for any assistance.
Code:
Public Sub MoveParty()Sheets("ECO").Select
    Cells.Select
    Selection.ClearContents
Sheets("BRO_20190910").Select
   Dim c As Range, CopyRange As Range, DataRange As Range
    Dim DestRange As Range
    Dim Lr As Long


    With ThisWorkbook
        With .Sheets("BRO_20190910") 'source sheet
            Lr = .Cells(.Rows.Count, 1).End(xlUp).Row
            Set DataRange = .Range(.Cells(1, 1), .Cells(Lr, 1))
        End With


        With .Sheets("ECO") 'destination sheet
            Lr = IIf(IsEmpty(.Range("A1").Value), 1, .Cells(.Rows.Count, 1).End(xlUp).Row + 1)
            Set DestRange = .Cells(Lr, 1)
        End With
    End With
    
    DataRange.EntireRow.Hidden = False
    
    For Each c In DataRange.Cells
        If c.Value = "ECO" Then
            If CopyRange Is Nothing Then
                Set CopyRange = c
            Else
                Set CopyRange = Union(CopyRange, c)
            End If
        End If
    Next c
    
    If Not CopyRange Is Nothing Then
    
    With CopyRange.EntireRow
        .Copy DestRange
        .Delete shift:=xlShiftUp
    End With
    
    End If


End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Make these changes
Rich (BB code):
With .Sheets("BRO_20190910") 'source sheet
    Lr = .Cells(.Rows.Count, 24).End(xlUp).Row
    Set DataRange = .Range(.Cells(1, 24), .Cells(Lr, 24))
End With
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top