Find Specific Value from Cell and Merged with Adjacent Cell

shahidsamikhan

New Member
Joined
Dec 4, 2014
Messages
17
Hi All,
I have a excel sheet where column A have sub total for each category. (No. of rows in attached sample file is not fixed)

I want to find sub total and merge that cell with adjacent cell then align entire row to center and align merged cell to left alignment with proper border formatting as showed in sample file.

I need solution in vba code.

Regards,
Shahid

Sample.xlsx
ABCDEFGHI
1ABCDEFGHTOTAL
2AAAAAA-111852118
3AAA-221254620
4Sub-Total3210106738
5BBBBBB-125218927
6BBB-211852118
7BBB-311852118
8BBB-421254620
9Sub-Total682016161783
10CCCCCC-111852118
11CCC-221254620
12CCC-325218927
13Sub-Total571211141665
14DDDDDD-121254620
15Sub-Total21254620
16EEEEEE-125218927
17EEE-211852118
18Sub-Total36106101045
19FFFFFF21254620
20Sub-Total21254620
21Grand Total212556535462271
Actual
Cell Formulas
RangeFormula
C18:I18,C4:I4C4=SUM(C2:C3)
C9:I9C9=SUM(C5:C8)
C13:I13C13=SUM(C10:C12)
C20:I20,C15:I15C15=SUM(C14)
I19,I16:I17,I14,I10:I12,I5:I8,I2:I3I2=SUM(C2:H2)
C21:I21C21=C4+C9+C13+C15+C18+C20


Output sheet:
Sample.xlsx
ABCDEFGHI
1ABCDEFGHTOTAL
2AAAAAA-111852118
3AAA-221254620
4Sub-Total3210106738
5BBBBBB-125218927
6BBB-211852118
7BBB-311852118
8BBB-421254620
9Sub-Total682016161783
10CCCCCC-111852118
11CCC-221254620
12CCC-325218927
13Sub-Total571211141665
14DDDDDD-121254620
15Sub-Total21254620
16EEEEEE-125218927
17EEE-211852118
18Sub-Total36106101045
19FFFFFF21254620
20Sub-Total21254620
21Grand Total212556535462271
Required
Cell Formulas
RangeFormula
C18:I18,C4:I4C4=SUM(C2:C3)
C9:I9C9=SUM(C5:C8)
C13:I13C13=SUM(C10:C12)
C20:I20,C15:I15C15=SUM(C14)
I19,I16:I17,I14,I10:I12,I5:I8,I2:I3I2=SUM(C2:H2)
C21:I21C21=C4+C9+C13+C15+C18+C20
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi, according to your attachment a VBA demonstration as a beginner starter without merging cells :​
VBA Code:
Sub Demo1()
           Dim Rf As Range, R&
    With [A1].CurrentRegion.Rows
           Set Rf = .Columns(1).Find("*Total")
        If Not Rf Is Nothing Then
                Application.ScreenUpdating = False
                [A2].Resize(.Count - 1).HorizontalAlignment = xlLeft
                R = Rf.Row
            Do
                With .Item(Rf.Row).Columns
                     .Font.Bold = True
                     .Item("A:B").HorizontalAlignment = 7
                     .Item("C:I").HorizontalAlignment = xlCenter
                End With
                   Set Rf = .Columns(1).FindNext(Rf)
            Loop Until Rf.Row = R
               .Borders.Weight = xlThin
                Application.ScreenUpdating = True
                Set Rf = Nothing
        End If
    End With
End Sub
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Find Specific Value from Cell and Merged with Adjacent Cell - OzGrid Free Excel/VBA Help Forum
also Find Specific Value from Cell and Merged with Adjacent Cell
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,576
Members
448,972
Latest member
Shantanu2024

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