Delete empty columns in CSV exported files by Excel

Hello there,

As you know, Jira exports issues to CSV (all fields) all associated custom fields, even if they are empty. So, when you import this CSV Jira also asks you to fill in mapping a lot of unnecessary custom fields. 

There is a short VBA script for Excel to delete all empty columns.

Sub DeleteEmptyCol()
Dim rng As Range
Dim backupHeader As Variant
Dim inputRng As Range
'Select all cells in the worksheet
Set inputRng = Range("A1").CurrentRegion
Application.ScreenUpdating = False
'Go through columns
For i = inputRng.Columns.Count To 1 Step -1
'Remember the current header name
backupHeader = inputRng.Cells(1, i).Value
'Remove the current header, if necessary we return it back later
inputRng.Cells(1, i).Clear
Set rng = inputRng.Cells(1, i).EntireColumn
If Application.WorksheetFunction.CountA(rng) = 0 Then
'delete column if all cells are empty
'Debug.Print "Delete " + backupHeader
rng.Delete
Else
'return header back if column contains data
'Debug.Print "Return " + backupHeader
inputRng.Cells(1, i).Value = backupHeader
End If
Next
Application.ScreenUpdating = True
End Sub

How-to:

  • Export issues to CSV
    export.png
  • Open exported CSV file in Excel. Please note, that in some cases Excel can't open a CSV correctly. In that case you can try import data from the CSV and copy header names.
  • Press alt+F11
  • In the opened window click 'Insert' -> 'Module' 
    insertModule.png
  • In the window paste the code
  • Press F5
  • The script should remove all empty columns

I hope this will be helpful.

Regards,
Andrey

1 comment

Marjorie
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 2, 2023

Thanks for this information, @Andrew 

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events