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: 
prabir_c
Partner - Creator
Partner - Creator

Insert blank row after each 3 record

Hello All,

I want to insert 3 blank row after each Data in a Excel.  following is my data-

data.JPG

I want the data as below format.

data2.JPG

This means I have to Copy the full data and  paste it in a excel.  Then Go to last data record and then using a for loop insert a blank row upto A2. Because A1 is the heading.

Please Help. !

1 Solution

Accepted Solutions
m_woolf
Master II
Master II

See the attached qvw

View solution in original post

11 Replies
m_woolf
Master II
Master II

See the attached qvw

tamilarasu
Champion
Champion

Hi,

I am using personal edition. So, I am not sure what you have tried. I prepared a sample file from your screenshot and attached the same.

Sub Test()
Dim XLApp, XLDoc, XLSheet 


FileName = "Test.xlsx"
FilePath = ActiveDocument.GetVariable("vVar").GetContent.
String


If Right(FilePath,1)<> "\" then
FilePath = FilePath & "\"
End If


File = FilePath & FileName

Set XLApp = CreateObject("Excel.Application") 
XLApp.
Visible = False 'True to display the excel
Set XLDoc = XLApp.Workbooks.Add
Set XLSheet= XLDoc.Worksheets("Sheet1")

ActiveDocument.GetSheetObject("TB01").CopyTableToClipboard
True
XLSheet.Paste

LastRow = XLSheet.Cells(XLSheet.Rows.Count, 1).
End(-4162).Row

For i = LastRow To 3 Step -1
XLSheet.Rows(i).Resize(3).InserT
Next

XLSheet.Range("A1").
Select
XLDoc.SaveAs File
XLApp.Application.quit 

Set XLApp = Nothing 
Set XLDoc = Nothing 
Set XLSheet = Nothing 
Msgbox "Exported Sucessfully" & VbNewline & vbNewline & "File path: " & File, vbInformation , "Export"
End Sub


If you have any issues, let me know.


prabir_c
Partner - Creator
Partner - Creator
Author

Thank You Tamil for your help.. It is working perfectly.

prabir_c
Partner - Creator
Partner - Creator
Author

Thanks m w fro your help.

tamilarasu
Champion
Champion

Prabir,

Great. I just opened your file and modified few lines of code. Attached the modified file. Hope it helps someone someday.

Not applicable

Hi Tamil,

How do you enter a blank row every time the text "Total" is found in the same column?

tamilarasu
Champion
Champion

Hi Clare,

Please find the attached file. Let me know If you have any questions.

Anil_Babu_Samineni

Tamil, I don't know what i did wrong here, would you suggest me here. Default when i am trying to hit the Button it goes to Code.

Sub ExcelFile

Dim XLApp, XLDoc, XLSheet 

FileName = "Z:\Test.xlsx"

FilePath = ActiveDocument.GetVariable("vVar").GetContent.String

If Right(FilePath,1)<> "\" then

FilePath = FilePath & "\"

End If

File = FilePath & FileName

Set XLApp = CreateObject("Excel.Application") 

XLApp.Visible = False 'True to display the excel

Set XLDoc = XLApp.Workbooks.Add

Set XLSheet= XLDoc.Worksheets("Sheet1")

ActiveDocument.GetSheetObject("TB01").CopyTableToClipboard True

XLSheet.Paste

LastRow = XLSheet.Cells(XLSheet.Rows.Count, 1).End(-4162).Row

For i = LastRow To 3 Step -1

XLSheet.Rows(i).Resize(3).InserT

Next

XLSheet.Range("A1").Select

XLDoc.SaveAs File

XLApp.Application.quit 

Set XLApp = Nothing 

Set XLDoc = Nothing 

Set XLSheet = Nothing 

Msgbox "Exported Sucessfully" & VbNewline & vbNewline & "File path: " & File, vbInformation , "Export"

End Sub

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
tamilarasu
Champion
Champion

Hi Anil,

You have to change the macro security setting like in the below picture.


Capture.PNG

Also I did a minor change in your code.

Sub ExcelFile

Dim XLApp, XLDoc, XLSheet

File = "Z:\Test.xlsx"

Set XLApp = CreateObject("Excel.Application")

XLApp.Visible = False 'True to display the excel

Set XLDoc = XLApp.Workbooks.Add

Set XLSheet= XLDoc.Worksheets("Sheet1")

ActiveDocument.GetSheetObject("TB01").CopyTableToClipboard True

XLSheet.Paste

LastRow = XLSheet.Cells(XLSheet.Rows.Count, 1).End(-4162).Row

For i = LastRow To 3 Step -1

XLSheet.Rows(i).Resize(3).InserT

Next

XLSheet.Range("A1").Select

XLDoc.SaveAs File

XLApp.Application.quit

Set XLApp = Nothing

Set XLDoc = Nothing

Set XLSheet = Nothing

Msgbox "Exported Sucessfully" & VbNewline & vbNewline & "File path: " & File, vbInformation , "Export"

End Sub