Home > Blockchain >  Copy filtered cell by color on another sheet without header
Copy filtered cell by color on another sheet without header

Time:01-27

i have the below code to filter from a sheet the yellow cells in column A and copy them on another sheet at the bottom of the values already present in the column A, however also the header is beeing copied and i need to exclude it, what's wrong in your opinion?

Sub CopyColor()



Dim wk As Workbook: Set wk = ThisWorkbook
Dim sht As Worksheet: Set sht = wk.Worksheets("Base Dati Old")
Dim sht1 As Worksheet: Set sht1 = wk.Worksheets("Prova")
Dim lr, lr1 As Long, rng As Range




'Define last used row;
lr = sht.Cells(sht.Rows.count, "A").End(xlUp).Row
lr1 = sht1.Cells(sht1.Rows.count, "A").End(xlUp).Row
Set rng = sht.Range("A2:A" & lr)

'Filter your data on yellow;
rng.AutoFilter 1, RGB(255, 255, 0), xlFilterCellColor

'Copy filtered cells;
rng.SpecialCells(12).Offset.Copy wk.Worksheets("Prova").Range("A" & lr1)



'Turn off filter
rng.AutoFilter



End Sub

CodePudding user response:

Try this:

rng.Offset(1,0).Resize(rng.Rows.count-1).SpecialCells(12).Copy _
       wk.Worksheets("Prova").Range("A" & lr1)
  •  Tags:  
  • Related