ayman helmy
New Member
- Joined
- Mar 17, 2021
- Messages
- 16
- Office Version
- 365
- Platform
- Windows
hello All
i use below code to copy filtered data and paste them is same range for Column Z
i need to edit it to contain more columns until column BI
i use below code to copy filtered data and paste them is same range for Column Z
i need to edit it to contain more columns until column BI
VBA Code:
Sub CopyToZ()
Dim ws As Worksheet: Set ws = ActiveSheet ' be more specific
' First Cell of the Data Range (in the row below headers)
Dim fCell As Range: Set fCell = ws.Range("Z3")
' Last Cell of the Filtered Range
Dim lCell As Range: Set lCell = ws.Range("Z" & ws.Rows.Count).End(xlUp)
' If no filtered data, the last cell will be the header cell, which
' is above the first cell. Check this with:
If lCell.Row < fCell.Row Then Exit Sub ' no filtered data
' Range from First Cell to Last Cell
Dim rg As Range: Set rg = ws.Range(fCell, lCell)
' Filtered Data Range
Dim frg As Range: Set frg = rg.SpecialCells(xlCellTypeVisible)
' Area Range
Dim arg As Range
For Each arg In frg.Areas
' Either copy values (more efficient (faster))...
arg.EntireRow.Columns("Z").Value = arg.Value
' ... or copy values, formulas and formatting
'arg.Copy arg.EntireRow.Columns("Y")
Next arg
End Sub
Last edited by a moderator: