Trying to sum a column with merged Cells

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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
 
Upvote 0
Solution

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

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