Solved

excel 2010 unmerge cells the populate blank cells with data from above

Posted on 2014-02-12
4
1,071 Views
Last Modified: 2014-02-12
Could an expert help me out with some VBA code on this one please.

I need to unmerge all cells then starting in first blank cell afetr cell 'A6' copy the data from the cell above.

Do the same from B7, C7, D7 and E7

so....if A6 has abc in it copy abc into A7 A8 etc until next non blank cell if A20 has xyz in it copy xyz into A21...... until next non blank etc etc.

Do the same from B7, C7, D7 and E7


Thanks in advance
0
Comment
Question by:Jagwarman
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 39852707
Try this:
Sub foo()
   Dim LastRow As Long
   ' use last populated row in column A
   LastRow = Cells(Rows.Count, "A").End(xlUp).Row
   
   With Range("A6:E" & LastRow)
      ' unmerge
      .MergeCells = False
      ' add formula referring to cell above in all blank cells
      .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
      ' paste formulas as values
      .Value = .Value
   End With
End Sub

Open in new window

0
 

Author Closing Comment

by:Jagwarman
ID: 39852753
brilliant thanks
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39852768
Hi is this what you want ?? Paste this code in the sheet that you need to convert or in a module.

Sub PasteAfter()
Dim WS As Worksheet
Dim ExcelLastCell As Object
Dim MaxRow As Long, I As Long, J As Long
Dim CelltoCopy

Set WS = ActiveSheet
WS.DisplayPageBreaks = False
Set ExcelLastCell = WS.Cells.SpecialCells(xlLastCell)
MaxRow = ExcelLastCell.Row
MaxCol = ExcelLastCell.Column
WS.UsedRange.UnMerge
CelltoCopy = WS.Range("A6")

For J = 1 To MaxCol
    For I = 6 To MaxRow
        If WS.Cells(I, J) <> "" Then
            CelltoCopy = WS.Cells(I, J)
        Else
            WS.Cells(I, J) = CelltoCopy
        End If
    Next I
    CelltoCopy = ""
Next J
End Sub

Open in new window


I copied in this workbook Sheet1 (original) as a backup. Press on the button Paste After in Sheet1 and check the results.

I started at row 6 as you explicitly said: After cell A6 don't know if this was an example and you want to do the whole sheet. If it is the case then replace in the routine this line
For I = 6 To MaxRow

by this Line
For I = 1 To MaxRow

gowflow
PasteAfter.xlsm
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39852771
Ooops I guess I was late !!!

Just a note in Rory solution if you happen to have no items in col A then the routine fails.
gowflow
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Formula 6 45
What is format f12.8 for a CSV file 6 37
Automating Excel Weekly Report 13 50
Excel Conditional Formatting in a Macro 4 25
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now