Consulting

Results 1 to 7 of 7

Thread: Copy formula down in next blank row andn hard paste previous results

  1. #1

    Copy formula down in next blank row andn hard paste previous results

    I have the following code which does what I want it do apart from it copies and pastes row 8 each time instead of the one above where the formula has been copied down from:

        Sheets("Data").Select
    
        LastRow = Range("C" & Rows.Count).End(xlUp).Row
    
    
    With Range("C8:L" & LastRow)
          .Copy .Offset(1)
          .Value = .Value
          .Offset(-1, 1)(1).Select
          
    
          End With


  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try:
    LastRow = Range("C" & Rows.Count).End(xlUp).Row
    With Range("C" & LastRow & ":L" & LastRow)
      .Copy .Offset(1)
      .Value = .Value
      .Offset(-1, 1)(1).Select
    End With
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3

    Works!

    Quote Originally Posted by p45cal View Post
    try:
    LastRow = Range("C" & Rows.Count).End(xlUp).Row
    With Range("C" & LastRow & ":L" & LastRow)
      .Copy .Offset(1)
      .Value = .Value
      .Offset(-1, 1)(1).Select
    End With
    That works perfectly!!

    Not sure if this is a separate post but can this be applied to a number of worksheets?

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    If the code is not in a sheet code-module it can apply to the active sheet, whichever that happens to be. If it is in a sheet's code-module it will only apply to that sheet.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    Thanks - what I meant was can this be an array type application.... so that it does it to a number of worksheets rather than having to name each sheet at a time and effectively loop through them? or is that the solution some sort of loop?

  6. #6
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Sub blah()
    For Each sht In Sheets(Array("Sheet1", "Sheet2", "Sheet3")) '<<adjust the sheets you want to process.
      With sht
        LastRow = .Range("C" & .Rows.Count).End(xlUp).Row
        With .Range("C" & LastRow & ":L" & LastRow)
          .Copy .Offset(1)
          .Value = .Value
          '.Offset(-1, 1)(1).Select 'can't select something on a sheet which isn't the active sheet.
        End With
      End With    'sht
    Next sht
    End Sub
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  7. #7
    Genius, thank you!!!

Posting Permissions

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