Copy certain cells in a row to another tab if value in column >= date()

zillmatic

New Member
Joined
Nov 5, 2019
Messages
2
I found a thread that was extremely helpful in copying entire rows when the value in a specified column > 0. However, I only want the values in columns A,B,C,D,G,S instead of the entire row.

The code I modified from Fluff's answer looks like:

Code:
Sub WeeklyReport()

Dim rng As Range
Dim cell As Range
Dim lr As Long
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = Sheets("Current")
Set ws2 = Sheets("ReportOut")


lr = ws1.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = ws1.Range("G1:G" & lr)


For Each cell In rng
    If cell.Value >= Date() Then
        cell.EntireRow.Copy
        If ws2.Range("A1").Value = "" Then
            ws2.Range("A1").PasteSpecial xlPasteValues
        Else
            ws2.Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValues
        End If
    End If
Next cell


Application.CutCopyMode = False
Range("A1").Select

End Sub

How would I do it if I only want certain columns instead of the entire row? I'd want the values in columns A,B,C,D,G,S from the first tab to paste in columns A,B,C,D,E,F in the second.

Alternatively I could copy the entire row, then at the end have it delete the columns I don't need. This may be a ton easier, but I'd also need to keep the formatting from the first tab in this case.

Thanks!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
How about
Code:
Sub WeeklyReport()

Dim rng As Range
Dim cell As Range
Dim lr As Long
[COLOR=#ff0000]Dim Ary As Variant[/COLOR]
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Set ws1 = Sheets("Current")
Set ws2 = Sheets("ReportOut")


lr = ws1.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = ws1.Range("G1:G" & lr)


For Each cell In rng
    If cell.Value >= Date Then
        [COLOR=#ff0000]Ary = Application.Index(cell.EntireRow, 1, Array(1, 2, 3, 4, 7, 19))[/COLOR]
        If ws2.Range("A1").Value = "" Then
            ws2.Range("A1").[COLOR=#ff0000]Resize(, 6).Value = Ary[/COLOR]
        Else
            ws2.Range("A" & Rows.Count).End(xlUp).Offset(1).[COLOR=#ff0000]Resize(, 6).Value = Ary[/COLOR]
        End If
    End If
Next cell


Application.CutCopyMode = False
Range("A1").Select

End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,948
Messages
6,122,420
Members
449,083
Latest member
Ava19

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