Solved

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

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
add a if, if vlookup returns a blank 5 21
Excel 3 22
Index/Match with Multiple Criteria 2 14
MIN, using ARRAY 4 15
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

708 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

19 Experts available now in Live!

Get 1:1 Help Now