Copy selected cells (with filter on) instead of the whole like

Aquila61

New Member
Joined
Oct 22, 2004
Messages
19
Hi guys

really long time not posting here, you know change in works, family... usual things!

got a probelm now hope you can help me about

(please note I know very little about VBA but I'm a good "copier"!!!!)

I have following code (clearly copied from the net, that's why I'm not able to solve my problem) that copies a selection from a workbook into another workbook after having inserted x number of rows. The main problem is that this code copies the whole line, while I need only the selected cells (ie from G to AA). the main issue I have/had is/was with filters, I've managed to get is almost work....!

here is the code (remember filter is on, so rows are not sequential)

Sub CopyFilter()
Dim Rng As Range
Dim rng2 As Range
Dim rng3 As Range
Dim aRng
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
MsgBox "No data to copy"
Else

Set rng3 = ActiveSheet.AutoFilter.Range

b = rng3.Columns(1). _
SpecialCells(xlCellTypeVisible).Count - 1

'MsgBox rng.Columns(1). _
SpecialCells(xlCellTypeVisible).Count - 1 _
& " of " & rng _
.Rows.Count - 1 & " Records"
'MsgBox "" & b

Workbooks("XXXXX").Activate
Range("a12").Activate

aRng = b
Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(aRng, 0)).Select

Selection.EntireRow.Insert
Range("a13").Activate

'Set Rng = ActiveSheet.AutoFilter.Range
rng3.Offset(1, 0).Resize(rng3.Rows.Count - 1).Copy _
Destination:=Worksheets("XXXXXS1").Range("A13")


End If
End Sub


Thanks guys and have a nice day!!
 

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

Forum statistics

Threads
1,224,587
Messages
6,179,735
Members
452,939
Latest member
WCrawford

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