Copy (visible) values in column after auto filter using VBA for Excel

dahveedoff

New Member
Joined
Jan 31, 2014
Messages
7
Ive got a vba script i am writing that I need help with.

So I am the stage where after auto filtering the dataset in Excel, I need to copy values down a column from a particular position. So what I have done is to identify the column header I need to copy values from, offset down two cells and then copy down to the last visible cell in that column.

I am using the resize() function to try to achieve that but it doesn't seem to be working. Can someone please help look at my code to identify where I'm going wrong?

Code:
Set ColHeader = Range("A1:XFD1").Find(arr1(k))ColHeader.Activate
ColHeader.Offset(2, 0).Select
ActiveCell.Resize(b).SpecialCells(xlCellTypeVisible).Select
Selection.Copy
ColHeader.Offset(1, 1).PasteSpecial Transpose:=True

"b" in the resize function is basically a calculation of how many visible rows are left in the column after autofiltering.

The last bit at the end is needed because I want to then transpose the values I have copied, across three columns next to the column header.

Thanks
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
The Resize method doesn't take into account the SpecialCells object, so your resize will be actual rows, not truncated by the SpecialCells object method(s). Instead, just use the entire range and qualify that by the SpecialCells(xlcelltypevisible) method.
 
Upvote 0
Thanks Zack. So when you say use the entire range you are talking about the UsedRange() function right?

I've kinda got a workaround now by using a couple of inner loops and assigning the some offset values to a range object dynamically and then just equating that to the value of another cell reference.

Thanks

David
 
Upvote 0
You can use the UsedRange object but I tend to stay away from it. While there are other methods, perhaps you can use something like this:

Code:
    Dim ColHeader As Range
    
    On Error Resume Next
    Set ColHeader = Range("A1:XFD1").Find(arr1(k))
    On Error GoTo 0
    
    If Not ColHeader Is Nothing Then
        With ColHeader.Offset(2, 0).Resize(ActiveSheet.UsedRange.Rows.Count - 2, 1)
            .SpecialCells(xlCellTypeVisible).Copy
            .Offset(-1, 1).PasteSpecial Transpose:=True
        End With
    End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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