baxtercavendish
New Member
- Joined
- Aug 27, 2009
- Messages
- 17
Trying to write a basic macro here that will go through a column searching for blank cells, and merge them with the first activecell.end(xlUP). Here is an example of the data:
Americas
(blank)
(blank)
Americas
(blank)
(blank)
(blank)
(blank)
Americas
Americas
Americas
(blank)
(blank)
Here is my current code, again, very basic:
Current issue is it will merge the first "Americas" with the following blanks, then the next "Americas" and blanks, but then it Selects both "Americas" that have been merged and presents this msgbox "The selection contains multiple data values. Merging into one cell will keep the upper-left most data only." Is there a way to get it to not select the multiple data values and move on to the next line to search and merge?
Results in:
Americas (merged 3 cells)
Americas (merged 5 cells)
both of which are now selected so that if you press Ok in the msgbox it turns into "Americas" (8 cells merged) and executes the next merge that has blank spaces (repeats same issue)
Americas
(blank)
(blank)
Americas
(blank)
(blank)
(blank)
(blank)
Americas
Americas
Americas
(blank)
(blank)
Here is my current code, again, very basic:
Code:
Sub merge()
For i = 1 To Rows.Count
If Cells(i + 1, 1) = "" Then
Cells(i, 1).Select
ActiveCell.End(xlDown).Select
ActiveCell.Offset(-1, 0).Select
Range(ActiveCell.Address, ActiveCell.End(xlUp)).Select
With Selection
.merge
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End If
Next i
End Sub
Current issue is it will merge the first "Americas" with the following blanks, then the next "Americas" and blanks, but then it Selects both "Americas" that have been merged and presents this msgbox "The selection contains multiple data values. Merging into one cell will keep the upper-left most data only." Is there a way to get it to not select the multiple data values and move on to the next line to search and merge?
Results in:
Americas (merged 3 cells)
Americas (merged 5 cells)
both of which are now selected so that if you press Ok in the msgbox it turns into "Americas" (8 cells merged) and executes the next merge that has blank spaces (repeats same issue)