[Solved] Merge macro or formula for same contents

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
chandrankrishnan
Posts: 63
Joined: Sat Mar 05, 2016 1:21 pm

[Solved] Merge macro or formula for same contents

Post by chandrankrishnan »

Hai all,Good day.

can anyone help me for the attached sheet with formula or macro program for two cells have the same contents means then result has been to be in merged format.

Attached file.

thanks in advance.
Attachments
merge.ods
(11.51 KiB) Downloaded 180 times
Last edited by Hagar Delest on Mon Sep 04, 2017 10:11 pm, edited 1 time in total.
Reason: tagged [Solved].
OpenOffice 4.1.2 windows vista
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: Merge macro or formula for same contents

Post by hubert lambert »

Hello,

Here's an example:

Code: Select all

sub addAndMerge()
    doc = thiscomponent
    sheet = doc.CurrentController.ActiveSheet
    sum = 0
    row = 2    
    first = row
    do 
        range = sheet.getCellRangeByPosition(3, row, 7, row+1)
        data = range.DataArray
        sum = sum + data(0)(3)
        
        if data(0)(0) <> data(1)(0) then
            sheet.getCellByPosition(7, first).setValue(sum)
            tobemerged = sheet.getCellRangeByPosition(7, first, 7, row)
            tobemerged.merge(True)
            sum = 0
            first = row + 1
        end if
        row = row +1
    loop until data(1)(0) = ""
end sub
Regards.
Attachments
chandrankrishnan.ods
(14.84 KiB) Downloaded 207 times
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
User avatar
chandrankrishnan
Posts: 63
Joined: Sat Mar 05, 2016 1:21 pm

Re: Merge macro or formula for same contents

Post by chandrankrishnan »

Hi hubert lambert ,
Thanks for the program its working fine.you saved my time and i trying this for past one week.

(can you please teach us to make simple macro program like this)

Thanks a ton. Have a Good day.
OpenOffice 4.1.2 windows vista
User avatar
chandrankrishnan
Posts: 63
Joined: Sat Mar 05, 2016 1:21 pm

Re: Merge macro or formula for same contents

Post by chandrankrishnan »

Hi
Can you please me to fine tune the program.i.e after sum result the serial number has to be generate as as same as total qty(i.e is in merged condition like 1,2,3 etc)

and then column "K" and "L" to be deleted.

Thanks in advance.
OpenOffice 4.1.2 windows vista
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: Merge macro or formula for same contents

Post by hubert lambert »

At your service... ;)
Attachments
chandrankrishnan.ods
(14.97 KiB) Downloaded 163 times
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
User avatar
chandrankrishnan
Posts: 63
Joined: Sat Mar 05, 2016 1:21 pm

Re: Merge macro or formula for same contents

Post by chandrankrishnan »

Hi
Good day to you.Program work fine,but one thing

after total qty sum(in merged form) i need continuous serial number to be generate(as mentioned in column I(marked in red color) like 1,2,3...

Thanks in advance.
Attachments
chandrankrishnan(2).ods
(14.36 KiB) Downloaded 171 times
OpenOffice 4.1.2 windows vista
User avatar
chandrankrishnan
Posts: 63
Joined: Sat Mar 05, 2016 1:21 pm

Re: Merge macro or formula for same contents

Post by chandrankrishnan »

Hi,
i tried once again with macro program,where its working for continuous serial for 2cell merge,whereas for 3cell merge, continuous serial number is collapsing that is its missing some numbers.

Can any one help me in this regards.

I had attached my entire work sheet with macro program.

Thanks in advance.
Attachments
SFO COMBINE MAC.ods
(24.29 KiB) Downloaded 174 times
OpenOffice 4.1.2 windows vista
hubert lambert
Posts: 145
Joined: Mon Jun 13, 2016 10:50 am

Re: Merge macro or formula for same contents

Post by hubert lambert »

Here it is:
chandrankrishnan.ods
(15.07 KiB) Downloaded 167 times
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
User avatar
chandrankrishnan
Posts: 63
Joined: Sat Mar 05, 2016 1:21 pm

Re: Merge macro or formula for same contents

Post by chandrankrishnan »

Hi hubert lambert ,
Thanks a ton.Its working fine and perfect.
Thankyou.
OpenOffice 4.1.2 windows vista
Post Reply