Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default if for merged cells

Hi all.
I want to make an if function to look for merged cells, and then add the
contents of another cell related to the merged cells.
I.e.,
if( c2:c_n is merged)
sum(d2:d_n)

where _n is the last cell of the merged/summed group.
How can I perform this function?
part of me is thinking a UDF, but since I'm not entirely familiar with them,
I would appreciate some direction.
Hope everyone has a great T-day weekend.
Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default if for merged cells

' This sub may be a start.
' It checks each cell in UsedRange.
' If C2:C4 are merged, it gets a hit
' on the merged cells 3 times.
' But it answers your example,
' giving =SUM($D$2:$D$4).

Sub Sub1()
Dim zCell As Range, iRowA&, iRowZ&, iCol%
For Each zCell In ActiveSheet.UsedRange
zCell.Select ' just to view
If zCell.MergeCells Then
' ck for merge type
If zCell.MergeArea.Columns.Count < 1 Then Stop ' ng
iRowA = zCell.Row
iRowZ = iRowA + zCell.MergeArea.Rows.Count - 1
iCol = zCell.Column + 1
zCell.Formula = "=sum(" & _
Cells(iRowA, iCol).Address & _
":" & _
Cells(iRowZ, iCol).Address & _
")"
End If
Next zCell
End Sub ' D-C Dave

SteveDB1 wrote:
Hi all.
I want to make an if function to look for merged cells, and then add the
contents of another cell related to the merged cells.
I.e.,
if( c2:c_n is merged)
sum(d2:d_n)

where _n is the last cell of the merged/summed group.
How can I perform this function?
part of me is thinking a UDF, but since I'm not entirely familiar with them,
I would appreciate some direction.
Hope everyone has a great T-day weekend.
Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default if for merged cells

Dave,
It appears to work. Thank you.
Next question. I noticed that it places the result in the merged area.
I would like to have the value placed where where I choose....
As previously stated, I'm looking at column C to determine if it's merged or
not (it will always have text in it.), and if so, to have values located in
column D to be summed over in another column/cell.

I want the sum valued results in column e. So, how would I place it there?

The UsedRange element, can I present that to look in a specific
column/range? if so, how would I write that statement? I ask that because my
worksheet will have 10 to 12 columns, and I only want it looking at the
merged rows of one specific column.

Again, thank you for your assistance.





"Dave D-C" wrote:

' This sub may be a start.
' It checks each cell in UsedRange.
' If C2:C4 are merged, it gets a hit
' on the merged cells 3 times.
' But it answers your example,
' giving =SUM($D$2:$D$4).

Sub Sub1()
Dim zCell As Range, iRowA&, iRowZ&, iCol%
For Each zCell In ActiveSheet.UsedRange
zCell.Select ' just to view
If zCell.MergeCells Then
' ck for merge type
If zCell.MergeArea.Columns.Count < 1 Then Stop ' ng
iRowA = zCell.Row
iRowZ = iRowA + zCell.MergeArea.Rows.Count - 1
iCol = zCell.Column + 1
zCell.Formula = "=sum(" & _
Cells(iRowA, iCol).Address & _
":" & _
Cells(iRowZ, iCol).Address & _
")"
End If
Next zCell
End Sub ' D-C Dave

SteveDB1 wrote:
Hi all.
I want to make an if function to look for merged cells, and then add the
contents of another cell related to the merged cells.
I.e.,
if( c2:c_n is merged)
sum(d2:d_n)

where _n is the last cell of the merged/summed group.
How can I perform this function?
part of me is thinking a UDF, but since I'm not entirely familiar with them,
I would appreciate some direction.
Hope everyone has a great T-day weekend.
Thanks.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default if for merged cells

Thanks Dave.
Bingo, got it!!!!
Thank you very much.
Have a great T-day/weekend.
Best.

"Dave D-C" wrote:

The major change here is the iRowZ = statement.

Sub Sub1()
' I only want it looking at the merged rows of column C.
Const iColMerge = 3
' values located in column D to be summed
Const iColFm = 4
' I want the sum valued results in column e
Const iColTo = 5
Dim zCell As Range, iRowV&, iRowZ&, iRowN&
' to find last used cell in column
iRowZ = Cells(Rows.Count, iColMerge).End(xlUp).Row
iRowV = 1
Do While iRowV <= iRowZ
Set zCell = Cells(iRowV, iColMerge)
zCell.Select ' just to view
If zCell.MergeCells Then
' ck for merge type
If zCell.MergeArea.Columns.Count < 1 Then Stop ' ng
iRowN = iRowV + zCell.MergeArea.Rows.Count - 1
Cells(iRowV, iColTo).Formula = "=sum(" & _
Cells(iRowV, iColFm).Address & _
":" & _
Cells(iRowN, iColFm).Address & _
")"
iRowV = iRowN + 1 '
Else
iRowV = iRowV + 1
End If
Loop
End Sub ' D-C Dave

SteveDB1 wrote:
Dave,
It appears to work. Thank you.
Next question. I noticed that it places the result in the merged area.
I would like to have the value placed where where I choose....
As previously stated, I'm looking at column C to determine if it's merged or
not (it will always have text in it.), and if so, to have values located in
column D to be summed over in another column/cell.

I want the sum valued results in column e. So, how would I place it there?

The UsedRange element, can I present that to look in a specific
column/range? if so, how would I write that statement? I ask that because my
worksheet will have 10 to 12 columns, and I only want it looking at the
merged rows of one specific column.

Again, thank you for your assistance.

"Dave D-C" wrote:
' This sub may be a start.
' It checks each cell in UsedRange.
' If C2:C4 are merged, it gets a hit
' on the merged cells 3 times.
' But it answers your example,
' giving =SUM($D$2:$D$4).

Sub Sub1()
Dim zCell As Range, iRowA&, iRowZ&, iCol%
For Each zCell In ActiveSheet.UsedRange
zCell.Select ' just to view
If zCell.MergeCells Then
' ck for merge type
If zCell.MergeArea.Columns.Count < 1 Then Stop ' ng
iRowA = zCell.Row
iRowZ = iRowA + zCell.MergeArea.Rows.Count - 1
iCol = zCell.Column + 1
zCell.Formula = "=sum(" & _
Cells(iRowA, iCol).Address & _
":" & _
Cells(iRowZ, iCol).Address & _
")"
End If
Next zCell
End Sub ' D-C Dave

SteveDB1 wrote:
Hi all.
I want to make an if function to look for merged cells, and then add the
contents of another cell related to the merged cells.
I.e.,
if( c2:c_n is merged)
sum(d2:d_n)

where _n is the last cell of the merged/summed group.
How can I perform this function?
part of me is thinking a UDF, but since I'm not entirely familiar with them,
I would appreciate some direction.
Hope everyone has a great T-day weekend.
Thanks



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy paste non merged to merged cells [email protected] Excel Worksheet Functions 1 February 5th 09 05:25 PM
How can I sort an Excel Doc containing merged & non-merged cells? KellyH Excel Discussion (Misc queries) 11 June 10th 08 04:12 AM
Autofit Merged cell Code is changing the format of my merged cells JB Excel Discussion (Misc queries) 0 August 20th 07 02:12 PM
how do i link merged cells to a merged cell in another worksheet. ibbm Excel Worksheet Functions 3 April 27th 06 11:40 PM
Sorting merged cellsHow do I sort merged cells not identically siz Laval Excel Worksheet Functions 1 November 3rd 04 09:40 PM


All times are GMT +1. The time now is 10:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"