Results 1 to 2 of 2

Using relative cell locations to copy in loop?

Threaded View

  1. #1
    Registered User
    Join Date
    11-09-2009
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Using relative cell locations to copy in loop?

    In reference to this thread I am trying to sort groups of rows based on a single cell in each group.

    I am going to try a brute force approach and run a loop that looks for the search criteria and copies this into a newly created first column for each of the rows in the group. I can then sort the groups using the first column.

    The cell I am looking for is in column F of every row that contains "C" in column B. I need to take this value, copy it, then paste it to column A for the 4 rows that comprise the group. The rows are the two rows above the row with "C", the same row as the row with "C", and the row below the row with "C".

    For example, I would need this code to find a value present in F3 and copy that value to A1:A4. I believe I would need to do this in relative terms as I am using a loop.

    I have attached a worksheet that manually shows what I am starting with and what I want to acheive (one worksheet for each). Please keep in mind that the attached workbook is just for illustration and shows only two groups of data points; this would need to loop through any number of data points.

       LastRow = Range("B65536").End(xlUp).Row
    
        For r = LastRow To 1 Step -1
            With Range("B" & r)
                If .Value = "C" Then
                
                Range("F" & r).Select
                Selection.Copy
                'How do I reference the cells to paste?
                ActiveSheet.Paste
                     
                End If
            End With
    Attached Files Attached Files
    Last edited by mpkavanagh; 02-16-2011 at 07:02 PM.

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