Consulting

Results 1 to 5 of 5

Thread: Sleeper: Copy a range of cells in a for loop

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Sleeper: Copy a range of cells in a for loop

    I have this for loop:

    Sub FindTotals()
    FinalRow = Cells(65536, 1).End(xlUp).Row
    For i = 2 To FinalRow
        If Cells(i, 4).Value = "JUNE" Then
           'Copy a range on the same row
           'Paste to another range on another worksheet
        End If
    Next i
    End Sub
    Need to copy a range of cells on the same row and paste it to another worksheet in say A1. How do you do that?
    Peace of mind is found in some of the strangest places.

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    I'm not 100% sure what you want but something like this might work.
    Sub FindTotals() FinalRow = Cells(65536, 1).End(xlUp).Row For i = 2 To FinalRow If Cells(i, 4).Value = "JUNE" Then Cells(i,4).EntireRow.Copy Worksheets("AnotherSheet").Range("A65536").End(xlUp) End If Next i End Sub

  3. #3
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    No just want to copy selected cells from the same row...
    Peace of mind is found in some of the strangest places.

  4. #4
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    austenr, the code that norie has posted copies the entire row, if that isn't what you want, then you need to select the range using VBA.
    Do you know what the range is?
    Has the range got a blank cell at the end of it?

  5. #5
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    Sorry....I think I have it figured out but the code may have some redundancies in it...I will post it later to see if it can be cleaned up.
    Peace of mind is found in some of the strangest places.

Posting Permissions

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