ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Looping macros using VB code (https://www.excelbanter.com/excel-discussion-misc-queries/16880-looping-macros-using-vbulletin-code.html)

accessuser1308

Looping macros using VB code
 
I am trying to loop a macro in excel. The macro will merge, for example,
cells F3:H3. I want the macro to perform the merge for all rows that have
data in column F. Does anybody know what code will make this work? Thanks
in advance.

Dave Peterson

Mergedcells can break lots of things. I only use them when I really, really
have to.

But how about something like:

Option Explicit
Sub testme01()

Dim myCell As Range
Dim myRng As Range

With ActiveSheet
Set myRng = .Range("f1", .Cells(.Rows.Count, "F").End(xlUp))
End With

For Each myCell In myRng.Cells
If IsEmpty(myCell) Then
'do nothing
Else
Application.DisplayAlerts = False
myCell.Resize(1, 3).Merge
Application.DisplayAlerts = True
End If
Next myCell

End Sub


accessuser1308 wrote:

I am trying to loop a macro in excel. The macro will merge, for example,
cells F3:H3. I want the macro to perform the merge for all rows that have
data in column F. Does anybody know what code will make this work? Thanks
in advance.


--

Dave Peterson

accessuser1308

This did exactly what I needed. Thank you very much

"accessuser1308" wrote:

I am trying to loop a macro in excel. The macro will merge, for example,
cells F3:H3. I want the macro to perform the merge for all rows that have
data in column F. Does anybody know what code will make this work? Thanks
in advance.



All times are GMT +1. The time now is 07:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com