+ Reply to Thread
Results 1 to 3 of 3

Copy and paste data if row in Column N is empty.

Hybrid View

  1. #1
    Registered User
    Join Date
    12-02-2009
    Location
    Omaha, Nebraska
    MS-Off Ver
    Excel 2003
    Posts
    7

    Copy and paste data if row in Column N is empty.

    Here is my current code

    Sub Demand()
    Sheets("Demand").Range("N2:N ").Value = _
    Sheets("Demand").Range("P2:P").Value
    Sheets("Demand").Range("Q2:P").Value
    Sheets("Demand").Range("S2:P").Value
    Sheets("Demand").Range("T2:P").Value
    Sheets("Demand").Range("V2:P").Value
    Sheets("Demand").Range("W2:P").Value
    Sheets("Demand").Range("Y2:P").Value
    Sheets("Demand").Range("Z2:P").Value
    Sheets("Demand").Range("AE2:P").Value
    Sheets("Demand").Activate
    End Sub
    I am trying to go down every row in Column N. If a row in Column N is empty I’d like to go to Column P copy the data and paste into Column N. If Column P is empty I’d like to go to Column Q copy the data and paste into Column N. If Column Q is empty I’d like to go to Column S copy the data and paste into Column N. If Column S is empty I’d like to go to Column T copy the data and paste into Column N. If column T is empty I’d like to go to Column V copy the data and paste into Column N. If Column V is empty go to Column W copy the data and paste into Column N. If Column W is empty go to Column Y copy the data and paste into Column N. If Column Y is empty go to Column Z copy the data and paste into Column N. If Column Z is empty go to Column AE copy the data and paste into Column N.

    As am I sure you can see my current macro will not accomplish what I am aiming to do. Can you help?
    Last edited by Hopper; 12-31-2009 at 03:26 PM. Reason: SOLVED

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Copy and paste data if row in Column N is empty.

    Welcome to the forum.

    Maybe like this:
    Sub Demand()
        Dim cell        As Range
        Dim v           As Variant
    
        For Each cell In Intersect(ActiveSheet.UsedRange, Columns("N"))
            If IsEmpty(cell.Value) Then
                For Each v In Array("P", "Q", "S", "T", "V", "W", "Y", "Z", "AE")
                    If Not IsEmpty(Cells(cell.Row, v).Value) Then
                        cell.Value = Cells(cell.Row, v).Value
                        Exit For
                    End If
                Next v
            End If
        Next cell
    End Sub
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    12-02-2009
    Location
    Omaha, Nebraska
    MS-Off Ver
    Excel 2003
    Posts
    7

    Solved

    Wow,Shg, this is a beautiful thing. Thank you for helping me with this bud; the macro is better than I imagined.
    Last edited by Hopper; 12-31-2009 at 03:26 PM. Reason: SOLVED

+ 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