Copy yellow fill colored items after last row containing items

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
Office Version
  1. 2021
Platform
  1. Windows
I have items in Col A to D on sheet6


where the items have a yellow fill color in Col D, then all the rows (Col A:D) are to be copied and pasted on sheet7 in Col A, but these items are to be posted in the last row after the last item in Col D on sheet7


I need this part of the code amended as it is not pasting after the last item in Col D


Code:
       wNew.Range("A" & j).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues

See full code below

Code:
 Sub CopyCOSYellowItems()
  Sheets(6).Select
  Dim LR As Long
  LR = Cells(Rows.Count, "A").End(xlUp).Row
  
  
  Dim wks As Worksheet
  Dim wNew As Worksheet
  Dim lRow As Long
  Dim x As Long
  Dim j As Long
  j = 1
  Set wks = Sheets(6)
  lRow = wks.Cells.SpecialCells(xlCellTypeLastCell).Row
  Set wNew = Sheets(7)
  For x = 2 To lRow
    If wks.Cells(x, 4).Interior.Color = vbYellow Then
        wks.Range("A" & x & ":D" & x).Copy
        wNew.Range("A" & j).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
        j = j + 1
    
    End If
  Next
  
  
  Application.CutCopyMode = False
  Sheets(7).Select
    Range("A1").EntireRow.Insert
    Range("D2:D" & LR).NumberFormat = "#,##0;(#,##0)"
    
    Range("A:D").EntireColumn.AutoFit
    
    
      
     wks.Range("a1:D1").Copy
     wNew.Range("A1").PasteSpecial Paste:=xlPasteValues
      
  Application.CutCopyMode = False
  
End Sub


It would be appreciated if someone could kindly assist me

I have also posted on the link below

https://www.excelforum.com/excel-pr...items-where-col-d-has-fill-colured-items.html
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Maybe this :
Code:
wNew.Range("D" & Rows.Count).End(xlUp).Offset(1, -3).PasteSpecial Paste:=xlPasteValues

In which case, j can be eliminated from the macro.
 
Upvote 0
I tried to amend code so that I pastes the data 2 rows after the last row where there is data in Col D, but it pastes the data in every second row


Code:
 wNew.Range("D" & Rows.Count).End(xlUp).Offset(2, -3).PasteSpecial Paste:=xlPasteValues
 
Upvote 0
I tried to amend code so that I pastes the data 2 rows after the last row where there is data in Col D, but it pastes the data in every second row


Code:
 wNew.Range("D" & Rows.Count).End(xlUp).Offset(2, -3).PasteSpecial Paste:=xlPasteValues

Do you mean that you want to leave one empty row after the last data row in Col D?
 
Upvote 0
Yes, I want to leave one empty row after the last data row in Col D
 
Upvote 0
Code:
Dim j As Long
j = 2
Set wks = Sheets(6)
lRow = wks.Cells.SpecialCells(xlCellTypeLastCell).Row
Set wNew = Sheets(7)
For x = 2 To lRow
  If wks.Cells(x, 4).Interior.Color = vbYellow Then
      wks.Range("A" & x & ":D" & x).Copy
      wNew.Range("D" & Rows.Count).End(xlUp).Offset(j, -3).PasteSpecial Paste:=xlPasteValues
      j = 1
  End If
Next
 
Upvote 0

Forum statistics

Threads
1,223,991
Messages
6,175,820
Members
452,672
Latest member
missbanana

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