Vba if cell = something then merge another range of cells

Josiah

Board Regular
Joined
Apr 10, 2008
Messages
178
If any cell in column B = 70 (actually, B18:B61), then merge the current row's cells in columns J, K and L

IE:
If Cell B40 = 70 then merge J40:L40
If Cell B50 = 70 then merge J50:L50
And so on...


How should I write this?

TIA!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I'm fuzzy on what is meant by merging the range? What happens to all the values in that range? Are they globbed together or is the first entered, etc....?
 
Upvote 0
Try:
Code:
Sub MergeCells()
    Application.ScreenUpdating = False
    Dim rng As Range
    For Each rng In Range("B18:B61")
        If rng = "70" Then
            Range("J" & rng.Row & ":L" & rng.Row).Merge
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
I'm fuzzy on what is meant by merging the range? What happens to all the values in that range? Are they globbed together or is the first entered, etc....?

The range wouldn't contain any data before merging.



ADDITION:

I also want the current row's range to UNMERGE if the cell that originally contains 70 is deleted.

IE:
If Cell B40 = 70 then merge J40:L40
If Cell B40 = "" then UNMERGE J40:L40 ("" = 70 is deleted)
 
Upvote 0
Trying your solution now mumps! I replied before I saw what you wrote. I'm sure the unmerge process will be simple
 
Upvote 0
Hm...I wasn't sure it mattered but I'm actually adding this as a private sub Worksheet_change (if that's the right terminology)

When I try it I get a NEXT WITHOUT FOR error...
 
Upvote 0

Forum statistics

Threads
1,203,521
Messages
6,055,883
Members
444,830
Latest member
Excelsmallbusinessmom

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