Results 1 to 13 of 13

Copy cell value above to cells below if blanks

Threaded View

  1. #1
    Forum Contributor
    Join Date
    12-16-2016
    Location
    Colorado, US
    MS-Off Ver
    2013
    Posts
    115

    Copy cell value above to cells below if blanks

    Hey Everyone,

    There is an issue im running into here and I cant figure it out.

    I have a program to take account numbers and separate them into single rows, once they populate into the new rows I want to get the blanks to fill with the information from the account in the rows adjacent to them. If I use the last row method the macro returns ref, but if I use a set number of rows this does not occur.

    Here is my current code.

    Sub TMPfriendly()
    
        Dim rindex As Long
        Dim saItem() As String
        Dim rng As Range
        Dim LastRow As Long
        Dim ws As Worksheet
    
        
            Set ws = ActiveSheet
            LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
            
            For rindex = Cells(Rows.Count, "A").End(xlUp).Row To 1 Step -1
                If InStr(Cells(rindex, "A").Value, "/") > 0 Then
                    saItem = Split(Cells(rindex, "A").Value, "/")
                    Rows(rindex + 1 & ":" & rindex + UBound(saItem)).Insert
                    Cells(rindex, "A").Resize(UBound(saItem) + 1).Value = WorksheetFunction.Transpose(saItem)
                End If
            Next rindex
            
            On Error Resume Next
              
              With Range("A2" & LastRow)
                On Error Resume Next
                    Set myRange = .SpecialCells(xlCellTypeBlanks)  'check for blank cells
                On Error GoTo 0
                    If Not myRange Is Nothing Then   'if there are blanks then...
                   myRange.FormulaR1C1 = "=R[-1]C"   'Formula to return data in cell above
                   .Value = .Value    'fix formula vales to fixed constant values
                   Else
                    End If
             End With
             
             Columns("B:B").Select
             ActiveSheet.Range("$A$1:$R" & LastRow).RemoveDuplicates Columns:=2, Header:=xlYes
             
    End Sub
    So it breaks column A into individual rows, and then scans for blanks, it should take the information from the cell above, and then copy that into the cell below for columns b-f (G-R) do not need to fill blanks at all they can be left as is.

    The problem is the worksheet can change length so I tried to add the last row, now I get REF! instead of the name from the cell above on any instance where there are multiple splits
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Find non-blanks cells and copy to another worksheet
    By A440 in forum Excel General
    Replies: 4
    Last Post: 10-04-2016, 07:57 AM
  2. [SOLVED] VBA Macros to Look for blanks cells and copy data
    By hecgroups in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2013, 02:26 AM
  3. [SOLVED] Copy cells from one worksheet to another while skipping blanks
    By gawk1980 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-23-2013, 05:02 PM
  4. Replies: 1
    Last Post: 10-24-2012, 01:21 PM
  5. copy cells ignoring blanks
    By twofootgiant in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-12-2011, 10:35 AM
  6. copy cells but miss blanks
    By wonderdunder in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-29-2010, 09:50 AM
  7. Copy cells to adjacent column, removing blanks
    By jbitluk in forum Excel General
    Replies: 8
    Last Post: 12-11-2009, 03:14 PM

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