Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Kushal_Chawda

Excel Merge Cells Macro Help

Currently I am using the macro to export to excel which is working fine and I get the below in excel

Capture.JPG

Here, " Actual Data" is the text object value.

Issue is I want to merge the header column to get the below format

Capture.JPG

stalwar1avinasheliterwunderlich gwassenaar

1 Solution

Accepted Solutions
trdandamudi
Master II
Master II

There are couple of ways you can do it.

Option I: You can center and merge excel data from Qlikview

Option II: You can have the complete macro in Excel and execute it from Qlikview.

In your case you should use Option I. Below is the macro code and I also attached the qlikview file, So that you can modify according to your need. Hope this helps..

SUB GenerateReport

DIM xlApp, xlBook

Const xlCenter = -4108

on error resume next

    Confirmation = MSGBOX ("Excel Summary Reports export has been initiated." & vbCrLf & _

        "Do you want to continue?"& vbCrLf &"",  36, "Export Confirmation")

  IF Confirmation = 7 THEN

      Exit Sub

  End IF

SET Doc = ActiveDocument

SET xlApp = CreateObject("Excel.Application")

SET xlBook = xlApp.Workbooks.Add

xlApp.Visible = True

xlApp.ScreenUpdating = False

  SET xlNewSheet = xlApp.Application.Worksheets.Add

  Doc.GetApplication.WaitForIdle

  'Copy the Text Box label and paste in Excel

  Doc.GetSheetObject("TX02").CopyTextToClipboard

  xlApp.ActiveSheet.Range("A1").Select

  xlApp.ActiveSheet.Paste  'Paste the table in Cell A1

  xlApp.ActiveSheet.Range("A1:C1").Merge

  xlApp.ActiveSheet.Range("A1:C1").HorizontalAlignment = xlCenter

  'Copy the table data and paste in Excel

  xlApp.ActiveSheet.Range("A2").Select

    Doc.GetSheetObject("TB02").CopyTableToClipBoard True

  xlApp.ActiveSheet.Paste  'Paste the table in Cell A2

  xlApp.ActiveSheet.Range("A1").Select

  xlApp.ScreenUpdating = True

  xlApp.Application.Quit

  SET objWorkbook = NOTHING    

  SET objExcel = NOTHING

End Sub

Merge_And_Center_Header_In_Excel.jpg

View solution in original post

7 Replies
tamilarasu
Champion
Champion

Can you post your macro or some sample document.?

marcus_sommer

You need to find these cells (+ select ?) and then add mergecells = true. Here a snippet from a more heavier routine of mine:

...

elseif CellMatrixThree(iFormatTyp)(2).Text = "MergeCells" then

     objExcelDoc.sheets(CellMatrixTwo(iObject)(1).Text).Range(arrFormatValues(iFormatValues)).Select

     objExcelDoc.sheets(CellMatrixTwo(iObject)(1).Text).Range(arrFormatValues(iFormatValues)).MergeCells = true

...


- Marcus

tamilarasu
Champion
Champion

Try something like this.

oSH.Range("A1:C1").Merge

vikasmahajan

Hi Kush,

I also looking for this Kushal Can you please attach excel and demo qvw after implementation.

Thanks

Vikas

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
trdandamudi
Master II
Master II

There are couple of ways you can do it.

Option I: You can center and merge excel data from Qlikview

Option II: You can have the complete macro in Excel and execute it from Qlikview.

In your case you should use Option I. Below is the macro code and I also attached the qlikview file, So that you can modify according to your need. Hope this helps..

SUB GenerateReport

DIM xlApp, xlBook

Const xlCenter = -4108

on error resume next

    Confirmation = MSGBOX ("Excel Summary Reports export has been initiated." & vbCrLf & _

        "Do you want to continue?"& vbCrLf &"",  36, "Export Confirmation")

  IF Confirmation = 7 THEN

      Exit Sub

  End IF

SET Doc = ActiveDocument

SET xlApp = CreateObject("Excel.Application")

SET xlBook = xlApp.Workbooks.Add

xlApp.Visible = True

xlApp.ScreenUpdating = False

  SET xlNewSheet = xlApp.Application.Worksheets.Add

  Doc.GetApplication.WaitForIdle

  'Copy the Text Box label and paste in Excel

  Doc.GetSheetObject("TX02").CopyTextToClipboard

  xlApp.ActiveSheet.Range("A1").Select

  xlApp.ActiveSheet.Paste  'Paste the table in Cell A1

  xlApp.ActiveSheet.Range("A1:C1").Merge

  xlApp.ActiveSheet.Range("A1:C1").HorizontalAlignment = xlCenter

  'Copy the table data and paste in Excel

  xlApp.ActiveSheet.Range("A2").Select

    Doc.GetSheetObject("TB02").CopyTableToClipBoard True

  xlApp.ActiveSheet.Paste  'Paste the table in Cell A2

  xlApp.ActiveSheet.Range("A1").Select

  xlApp.ScreenUpdating = True

  xlApp.Application.Quit

  SET objWorkbook = NOTHING    

  SET objExcel = NOTHING

End Sub

Merge_And_Center_Header_In_Excel.jpg

Kushal_Chawda
Author

thanks trdandamudi works fine.

trdandamudi
Master II
Master II

You're welcome and glad that you are able to use it.