Looping macros using VB code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top