+ Reply to Thread
Results 1 to 4 of 4

Using VBA to move a set number of columns

  1. #1
    Registered User
    Join Date
    01-27-2005
    Posts
    2

    Using VBA to move a set number of columns

    Help,

    I am trying to get VBA to go to the end of a column and then go (3) columns over and get the value from that cell and place in another location to set the maximum range on a chart. I can get VBA to do everything but move left or right.

    I should have paid more attention in school

    Thanks,
    Brian

  2. #2
    Forum Contributor
    Join Date
    11-16-2004
    Posts
    282
    From the Visual Basic Help files:

    Offset Property (Range Object)


    Returns a Range object that represents a range that’s offset from the specified range. Read-only.

    Syntax

    expression.Offset(RowOffset, ColumnOffset)

    expression Required. An expression that returns a Range object.

    RowOffset Optional Variant. The number of rows (positive, negative, or 0 (zero)) by which the range is to be offset. Positive values are offset downward, and negative values are offset upward. The default value is 0.

    ColumnOffset Optional Variant. The number of columns (positive, negative, or 0 (zero)) by which the range is to be offset. Positive values are offset to the right, and negative values are offset to the left. The default value is 0.

    Offset Property (Range Object) Example

    This example activates the cell three columns to the right of and three rows down from the active cell on Sheet1.

    Worksheets("Sheet1").Activate
    ActiveCell.Offset(rowOffset:=3, columnOffset:=3).Activate

    Hope this helps,
    theDude

  3. #3
    Registered User
    Join Date
    01-27-2005
    Posts
    2

    Almost there,

    I used the offset function, but still can not get the cells to move horizontally. Vertically is not a problem. Here is the code that I have so far:


    Worksheets("AFE Days & Cost").Activate
    Range("N6").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(RowOffset = 0, ColumnOffset = 3).Activate
    Selection.Copy
    Range("F29").Select
    ActiveSheet.Paste

    By changing the RowOfset to any number the selected cell moves accordingly, but the ColumnOffset value has no effect.

  4. #4
    Forum Contributor
    Join Date
    11-16-2004
    Posts
    282
    Use this EXACTLY as it appears (notice the BOLD code below is different than yours; a small 'r' for rowOffset, a small 'c' for columnOffset, and the ':' before each equal sign):

    ActiveCell.Offset(rowOffset:=0, columnOffset:=3).Activate

    Hope this helps,
    theDude

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1