Trying to sum a column with merged Cells

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
610
Office Version
  1. 2019
Platform
  1. Windows
I am having a very bad day trying to make this work.
Column K has quite a few cells which are merged together I am trying to skip over them but keep coming up against a brick wall.
The excel sheet cannot be altered as it is a template.
Thanks in advance

VBA Code:
Private Sub AllocHours()

TurnOff
Dim iRow As Integer
Dim LRow As Long, i As Long
Dim ws As Worksheet
Dim RangeRow As Range, Rng As Range, MyCell As Range, Rrg As Range


 
Set ws = ThisWorkbook.Worksheets("Job Card Master")

Set RangeRow = ws.Range("A13:A" & ws.UsedRange.Rows.Count).Find("TOTAL BODY SHOP HOURS", LookIn:=xlValues, LookAt:=xlWhole)

LRow = ws.Range("A" & Rows.Count).End(xlUp).Row


    If Not RangeRow Is Nothing Then
    iRow = RangeRow.Row
    End If

   If ws.Range("K13:K" & LRow).MergeCells = True Then
   Set Rng = ws.Range("K13:K" & LRow)
  End If
 
   For Each Rng In ws.Range("K13:K" & LRow)
 
   For i = 13 To Rng.Rows.Count
   Set Rrg = Rng.Rows(i)
   Set MyCell = ws.Cells(iRow, 11)
   MyCell.Value = WorksheetFunction.Sum(Range("K13:K" & Rrg.Value))
    Next i
  
Next

TurnOn

End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,643
Office Version
  1. 365
Platform
  1. Windows
The answer could be found like this:

VBA Code:
Dim RangeRow As Range

With Worksheets("Job Card Master")
    Set RangeRow = .Range("A13:A" & .Rows.Count).Find("TOTAL BODY SHOP HOURS", LookIn:=xlValues, LookAt:=xlWhole)
    If Not RangeRow Is Nothing Then
        .Cells(RangeRow.Row, 11) = Application.Sum(.Range(.Cells(1, 11), .Cells(RangeRow.Row - 1, 11)))
    End If
End With
 
Solution

Forum statistics

Threads
1,144,246
Messages
5,723,220
Members
422,485
Latest member
Tameima

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
Top