Problem with Offset, unable to get the right Syntax

darekknox

New Member
Joined
Feb 19, 2015
Messages
31
Hi All,

I have a trouble with the following line of the code:

Code:
 Sheets("Tab2").Select
    Rows("5:5").Select
    range("K5").Activate
    Selection.AutoFilter
    ActiveSheet.range("$A$5:$m$5").AutoFilter Field:=11, Criteria1:="<>"


    ActiveSheet.UsedRange.Offset(5, 0).SpecialCells _
       (xlCellTypeVisible).Copy

This works great, it copies data without header but I would also like it to copy 6 colums less.
I have tried

Code:
   ActiveSheet.UsedRange.Offset(5, -6).SpecialCells _
       (xlCellTypeVisible).Copy

But it gives me Object defining error.

Could you please help me?
 
Last edited:
Re: Problem with Offset, unable to get thew right Syntax

It gives $A$1:$r$18

I want it to copy from column A to G
Assuming Column K contains constants (that is, no formulas), then if I understand your originally posted code coupled with the above statement correctly, I think this single line of code will do what all of your code was attempting to do...
Code:
[table="width: 500"]
[tr]
	[td]Intersect(Range("K5", Cells(Rows.Count, "K").End(xlUp)).SpecialCells(xlConstants).EntireRow, Columns("A:G")).Copy[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Re: Problem with Offset, unable to get thew right Syntax

Thank you all for help, topic can be closed.

Issue solved with the following line:

Code:
Range(Range("a6"), Cells(Rows.Count, "g").End(xlUp)).SpecialCells(xlVisible).Copy
 
Upvote 0
Re: Problem with Offset, unable to get thew right Syntax

Thank you all for help, topic can be closed.

Issue solved with the following line:

Code:
Range(Range("a6"), Cells(Rows.Count, "g").End(xlUp)).SpecialCells(xlVisible).Copy
I am curious as to whether you tried my one-line replacement for all the code you posted in your original message and, if so, did it in fact work for you.
 
Upvote 0
Re: Problem with Offset, unable to get thew right Syntax

Hi Rick sorry for my late response. I just checked it (sorry I did not notice your post before). Code provided by you works, it copies the required range but with headers.
 
Last edited:
Upvote 0
Re: Problem with Offset, unable to get thew right Syntax

Hi Rick sorry for my late response. I just checked it (sorry I did not notice your post before). Code provided by you works, it copies the required range but with headers.
If Row 5 is your header row, then we just need to change the 5 in my code line to a 6...
Code:
[table="width: 500"]
[tr]
	[td]Intersect(Range("K[B][COLOR="#0000FF"]6[/COLOR][/B]", Cells(Rows.Count, "K").End(xlUp)).SpecialCells(xlConstants).EntireRow, Columns("A:G")).Copy[/td]
[/tr]
[/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,095
Messages
6,123,072
Members
449,093
Latest member
ripvw

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