Wednesday 3 October 2012

Merge Same Value Cells of Excel

Steps to Merge Same Value Cells in Excel

Create an Excel Sheet

Month Salary Emp Name
January 1000 Gulab
January 5000 Chand
January 89900 Maurya
Feb 93829 Rohit
Feb 73827 Shivansh
March 798989 Maurya
March 232 Shiv


Create New Macro
to create new macro press alt+f8

view this video for help

macro code used in video is given below:-


Sub MergeSame()
Dim r As Range, c As Range
Dim i As Long, j As Long
Set r = Range("A1", Cells(Rows.Count, "A").End(xlUp))

Application.ScreenUpdating = False
Application.DisplayAlerts = False

For i = 1 To r.Count
Set c = r(i)
j = 0
Do Until c <> c.Offset(rowoffset:=1)
Set c = c(2)
j = j + 1
Loop
With Range(r(i), c)
.Merge
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
i = i + j
Next i

Application.DisplayAlerts = True
Application.ScreenUpdating = True
DoEvents
End Sub

alfter running macro the result is show below


Month Salary Emp Name
January 1000 Gulab
5000 Chand
89900 Maurya
Feb 93829 Rohit
73827 Shivansh
March 798989 Maurya
232 Shiv

Regards
Ram Rati



No comments:

Post a Comment