CDR.cvs dump file VBA help needed.

thinkloko

New Member
Joined
Dec 13, 2017
Messages
1
I dumped some CDR files from our phone system and I need to sort out the data in the CVS file. Doing it manually takes almost all day long to do it as we get countless calls. I found this code online which works great to delete all the columns I don't need. However, it's only doing part of what I need to do.

Other things I would like to do to the file are:


Change time from epoch "xxxxxxxxxx" to time "dd/mm/yy hh:mm:ss"
Autofit Column Width
Change the column names from "dateTimeOrigination" to "Date Time" ect.
Apply this automatically to any CDR.cvs dump file I open.


I am using Excel 2016.Thanks!!!!


Sub deleteIrrelevantColumns()
Dim keepColumn As Boolean
Dim currentColumn As Integer
Dim columnHeading As String


currentColumn = 1
While currentColumn <= ActiveSheet.UsedRange.Columns.Count
columnHeading = ActiveSheet.UsedRange.Cells(1, currentColumn).Value


'CHECK WHETHER TO KEEP THE COLUMN
keepColumn = False
If columnHeading = "dateTimeOrigination" Then keepColumn = True
If columnHeading = "callingPartyNumber" Then keepColumn = True
If columnHeading = "originalCalledPartyNumber" Then keepColumn = True
If columnHeading = "finalCalledPartyNumber" Then keepColumn = True
If columnHeading = "dateTimeConnect" Then keepColumn = True
If columnHeading = "dateTimeDisconnect" Then keepColumn = True
If columnHeading = "lastRedirectDn" Then keepColumn = True
If columnHeading = "duration" Then keepColumn = True




If keepColumn Then
'IF YES THEN SKIP TO THE NEXT COLUMN,
currentColumn = currentColumn + 1
Else
'IF NO DELETE THE COLUMN
ActiveSheet.Columns(currentColumn).Delete
End If


'LASTLY AN ESCAPE IN CASE THE SHEET HAS NO COLUMNS LEFT
If (ActiveSheet.UsedRange.Address = "$A$1") And (ActiveSheet.Range("$A$1").Text = "") Then Exit Sub
Wend


End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Welcome to the Board!

Autofit Column Width
Change the column names from "dateTimeOrigination" to "Date Time" ect.
You should be able to get this code pretty easily by using the Macro Recorder and record yourself performing these steps manually (the Macro Recorder is a great tool for getting code snippets!).

Change time from epoch "xxxxxxxxxx" to time "dd/mm/yy hh:mm:ss"
Can you provide some examples of what these dates look like (and what those examples need to look like afterwards)?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

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