Solved

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

Posted on 2014-02-12
4
1,278 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 31

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 31

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

630 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