problem with counting Merge area cells

ajaypal_sp

New Member
Joined
Feb 11, 2015
Messages
25
HI



I wrote a VBA code by using Sumifs function. in this code i find out starting column number (for each category box), ending column number based on merged cells. by using #selection.columns.count# . sometimes this formula returns 1 even though there are 6 cells in Mergearea. When we run the code by using F5, this line of code is not working properly. Please help me.

in my code the below part is not working properly. i used below code 10 times in VBA module.

Code:
With ThisWorkbook.Worksheets("ks sales").Range("a2:az2")
Set sc = .Find("BYOD TRANSACTIONS")
If Not sc Is Nothing Then
sc = sc.Column


n = [COLOR=#0000cd][B]Cells(2, sc).MergeArea.Columns.Count[/B][/COLOR]


ec = n + sc - 1
End If
End With

Here,
sc - start column
n - no of cells in merge area.
ec - end column

Thank you in advance.

Regards
shiva
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
It counts columns not cells.


thank you for reply.

What ever, either columns or cells. NNo issue. result is same. But that line of code not working properly. when we use f5 , code skipping few lines / that line of code (count merge cells) returns value 1. i can't understand where the code was wrong.
 
Upvote 0
2nd row and 11th row contains merged cells. based on these merged cells i find out start & end columns to get result.
 
Last edited:
Upvote 0
If you want it to be on the worksheet within the with statement use a dot before cells ie .Cells(2,sc) etc
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,011
Members
448,935
Latest member
ijat

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