Trying to merge cells across with * at the start of the text

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
Find the * in a text string then merge the text across the columns.
At the moment it seems to just merge a load of random cells

VBA Code:
Sub MergeCells()
    Dim myFirstRow As Long
    Dim myLastRow As Long
    Dim myCriteriaColumn As Long
    Dim myFirstColumn As Long
    Dim myLastColumn As Long
    Dim ws As Worksheet
    Dim myCriteria As String
    Dim iCounter As Long
 
    myFirstRow = 13
    myCriteriaColumn = 5
    myFirstColumn = 5
    myLastColumn = 14
    myCriteria = "Merge cells"
 
    Set ws = ThisWorkbook.Worksheets("Job Card with Time Analysis")
 
    With ws
 
        myLastRow = .Cells.Find(What:="*", LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
 
        For iCounter = myLastRow To myFirstRow Step -1
            If .Cells(iCounter, myCriteriaColumn).Value = myCriteria Then .Range(.Cells(iCounter, myFirstColumn), .Cells(iCounter, myLastColumn)).Merge
        Next iCounter
 
    End With
 

End Sub
 
Are the cells to the right completely empty?

Nullstrings from imported data, formulas that show "", etc. would mean that the cells are not empty so it will not spill over then.

Other than such content in the cells, I know of no reason why it would not work as normal.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Data is from Access Database so properly are null. Can you override this?
 
Upvote 0
Only by deleting the nullstrings from those cells.

Assuming that there is no actual data anywhere to the right of column E
VBA Code:
ThisWorkbook.Worksheets("Job Card with Time Analysis").Range("F:N").ClearContents
 
Upvote 0
There is data to the right of the E column in rows without a * in them.
 
Upvote 0
Give this a go on a copy of your file
VBA Code:
Sub test
Dim c As Range, lRow As Long
With Worksheets("Job Card with Time Analysis")
    lRow = .Cells(Rows.Count,5).End(xlUp).Row
    For Each c In .Range("E13:E" & lRow)
        If Left(c.Value,1) ="*" Then c.Offset(,1).Resize(,9).ClearContents
    Next
End With
End Sub
 
Upvote 0
Try selecting some of the 'empty' cells in a row with * then hit the delete key to clear them and see if the text flows across.

I've tested the code above and it works fine for me, if it is not working for you then there is a problem with your sheet that needs to be identified.
 
Upvote 0
Try selecting some of the 'empty' cells in a row with * then hit the delete key to clear them and see if the text flows across. I have done that earlier it didn`t work?

I've tested the code above and it works fine for me, if it is not working for you then there is a problem with your sheet that needs to be identified.
 
Upvote 0
As long as the cell(s) immediately to the right are empty then the text will spill into them. If selecting them and clearing the contents is not allowing the text to spill then it would appear that something is wrong with your excel installation. I have made multiple attempts to recreate the problem without success, and have been through excel settings carefully and can find nothing that would cause the issue.

Without access to the workbook, I don't see that there is any way to identify the cause of the problem.
 
Upvote 0
Morning Jason75

Could I let you access my workbook?
Happy to send it to you via Dropbox on this forum.
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,310
Members
449,152
Latest member
PressEscape

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top