Copy certain columns versus entire row from one worksheet to another based on text entered in single colum

rlundbulls23

New Member
Joined
Dec 21, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

I've been using the following successfully but now want to modify it to only copy certain columns versus the entire row. I've read various threads but stuck how to include a range or identify specific columns.
Thanks in advance for your help!!

-Bob


Sub CopyRowBasedOnCellValue()

Dim xRg As Range

Dim xCell As Range

Dim A As Long

Dim B As Long

Dim C As Long

A = Worksheets("Master").UsedRange.Rows.Count

B = Worksheets("Sold").UsedRange.Rows.Count

If B = 1 Then

If Application.WorksheetFunction.CountA(Worksheets("Sold").UsedRange) = 0 Then B = 0

End If

Set xRg = Worksheets("Master").Range("D1:D" & A)

On Error Resume Next

Application.ScreenUpdating = False

For C = 1 To xRg.Count

If CStr(xRg(C).Value) = "Done" Then

xRg(C).EntireRow.Copy Destination:=Worksheets("Sold").Range("A" & B + 1)

B = B + 1

End If

Next

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Change the range (in red) to match the columns you want to copy.
Rich (BB code):
Sub CopyData()
    Application.ScreenUpdating = False
    Dim lRow As Long, srcWS As Worksheet, desWS As Worksheet
    Set srcWS = Sheets("Master")
    Set desWS = Sheets("Sold")
    Dim v As Variant, i As Long
    With srcWS
        lRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        v = .Range("D1:D" & lRow).Value
        For i = LBound(v) To UBound(v)
            If v(i, 1) = "Done" Then
                Intersect(.Rows(i), .Range("A:A,E:E,G:G")).Copy desWS.Cells(desWS.Rows.Count, "A").End(xlUp).Offset(1, 0)
            End If
        Next i
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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