+ Reply to Thread
Results 1 to 3 of 3

Copy cell and offset cell to third sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    06-03-2004
    Posts
    4

    Copy cell and offset cell to third sheet

    I have a search routine that once it finds something, it copies the cell and pastes the contents into a third worksheet in column 1.

    I now need to have it also copy the contents of a cell four columns to the left or three columns to the right (depending on the worksheet - logic already works for this) and paste the contents of both into the third worksheet in columns 1 and 2.

    I cannot set the second cell to active in order to copy it.

    Here is my current code:

    ' copy cell
    Cells(iRow, iCol).Copy
    ' paste into column1 of Results
    shkpt.Cells(kRow, 1).PasteSpecial _
    xlPasteValues, , False, False

    What I need is:

    ' copy cell
    Cells(iRow, iCol).Copy
    ' copy cell three columns to right
    ???
    ' paste first cell into column1 of Results
    shkpt.Cells(kRow, 1).PasteSpecial _
    xlPasteValues, , False, False
    ' paste second cell into column2 (kRow, 2) of Results
    ???

    and

    ' copy cell
    Cells(iRow, iCol).Copy
    ' copy cell four columns to left
    ???
    ' paste first cell into column1 of Results
    shkpt.Cells(kRow, 1).PasteSpecial _
    xlPasteValues, , False, False
    ' paste second cell into column2 (kRow, 2) of Results
    ???

    Thanks in advance.

  2. #2
    Forum Contributor
    Join Date
    11-16-2004
    Posts
    282
    Here's one way:
    ' Cell 3 columns to right...
    val2 = Cells(iRow, iCol + 3).Value
    ' Cell 4 columns to left...
    val3 = Cells(iRow, iCol - 4).Value
    ' Insert values to columns 1 & 2...
    shkpt.Cells(kRow, 1).Value = val2
    shkpt.Cells(kRow, 2).Value = val3
    Hope this helps,
    theDude

  3. #3
    Registered User
    Join Date
    06-03-2004
    Posts
    4
    Yes, thanks. It didn't like the negative offset so had to do a workaround but this got me where I needed in order to start.

+ 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