Solved

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

Posted on 2014-02-12
4
1,199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 30

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 30

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
A WS within a WS 11 41
NEED TO DO 2 OR 3 OR 4 NUMBERS LOOK UP 2 23
Userform to show a range in excel. 3 33
multiple unique values in different columns 15 36
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
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.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

734 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