Offset Query :: MrExcel Message Board


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

Offset Query
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

Ampleford
Board Master


Joined: 27 Mar 2002
Posts: 150
Location: Scotland
Flag: Scotland

Status: Offline

 Reply with quote  

Offset Query

I would like to copy a range of data, (Range A1:T1) then paste that data a set number of rows down within a table on another tab. That number of rows is found in cell A2

so far I have :-

dim OS as Integer
OS = Sheets("1").Range("A2").Value
Sheets("1").Activate
Range("A1:T1").Copy
Sheets("2").Activate
Range("A1",offset(0,OS)
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False


would this work ?

Post Sat Sep 20, 2003 12:17 pm 
 View user's profile Send private message Send e-mail Visit poster's website

Richie(UK)
MrExcel MVP


Joined: 18 May 2002
Posts: 2464
Location: Worcester, England
Flag: Uk

Status: Offline

 Reply with quote  

Re: Offset Query

Hi,

First off, whenever somebody asks "would this work ?" the obvious response is "Have you tried it ?" icon_wink.gif

You were on the right track with the Offset method - you just needed to check the VBE Help files regarding its implementation. Its also worth noting that Excel works in (Row,Column) order with its various operations, so you needed to have the OS variable as the first argument (its also worth getting into the habit of declaring your row variables as Longs - Integers will not always be adequate).

code:
Sub Test()
    Dim OS As Long
   
    With Sheet1
        OS = .Range("A2").Value
        .Range("A1:T1").Copy
        Sheet2.Range("A1").Offset(OS, 0).PasteSpecial _
            Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    End With
   
End Sub


HTH
_________________
Richie

Post Sat Sep 20, 2003 1:29 pm 
 View user's profile Send private message

Ampleford
Board Master


Joined: 27 Mar 2002
Posts: 150
Location: Scotland
Flag: Scotland

Status: Offline

 Reply with quote  

Re: Offset Query

i was writing the code as i was writing the query if you get my drift....

i tried it and it didn't work, but it's up and running now, thanks for your help. btw - what's a "Long" - i understand integer and string - but that's about it ....

cheers


trevor

Post Sat Sep 20, 2003 1:38 pm 
 View user's profile Send private message Send e-mail Visit poster's website

Richie(UK)
MrExcel MVP


Joined: 18 May 2002
Posts: 2464
Location: Worcester, England
Flag: Uk

Status: Offline

 Reply with quote  

Re: Offset Query

Hi trevor,

A 'Long' is just another data type. The following link, which details the various types available, should prove useful:

http://www.beyondtechnology.com/vba008.shtml

HTH
_________________
Richie

Post Sat Sep 20, 2003 2:45 pm 
 View user's profile Send private message
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.