Convert excel to CSV format using a join

JoeRooney

Board Regular
Joined
Nov 27, 2017
Messages
132
Hi

I am hoping someone can help me with the below. I have the below code and it almost doing what I need it to do

The below code will join my columns like this:

policy_id;"trans_process_date;"trans_type;"trans_reason;

But I need it to join them like this

policy_id;"trans_process_date";"trans_type";"trans_reason";

I need the ; separator to come after the " when joining each column.

I am sure it is obvious what needs to be changed but I cant work it out , any help with this is greatly appreciated.

Thanks

VBA Code:
Sub V1_Policy_Creator()

    Columns("A:A").Select
    Application.CutCopyMode = False
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Rows("1:1").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "V.1 Policy"
    
    Dim i As Long
    Dim Lastrow As Long
    Lastrow = Range("B" & Rows.Count).End(xlUp).Row

    For i = 2 To Lastrow
        Range("A" & i).Formula = Join(Application.Index(Range("B" & i & ":DE" & i).Value, 1, 0), ";" & """")
    Next i
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
67,955
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
        Range("A" & i).Formula = Join(Application.Index(Range("B" & i & ":DE" & i).Value, 1, 0), """;""")
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
67,955
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

JoeRooney

Board Regular
Joined
Nov 27, 2017
Messages
132

ADVERTISEMENT

Hi I need to make a slight adjustment to the below code

The problem is on the first cell , the codes reports it as:

policy_id;";"trans_process_date";"trans_type";

But I need to report it as

policy_id;"trans_process_date";"trans_type";

It is only affecting the first cell the rest of the range is perfect.

The code for V1_Policy_Creator2() was missing the ; after the first cell so I thought if I add it before i run the V1_Policy_Creator2() code this would resolve it but unfortunately not.

VBA Code:
Sub V1_Policy_Creator1()

 Dim i As Long
    Dim Lastrow As Long
    Lastrow = Range("B" & Rows.Count).End(xlUp).Row

 Columns("A:A").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A1").Select
    Selection.NumberFormat = "General"
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "=RC[1]&"";"""
    Range("A1").AutoFill Destination:=Range("A1:A" & Lastrow)
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Range("B1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Columns("A:A").Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    Range("A1").Select
    
    Call V1_Policy_Creator2
    
    End Sub
    
Sub V1_Policy_Creator2()

Columns("A:A").Select
    Application.CutCopyMode = False
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Rows("1:1").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "TOM Policy"
    
    Dim i As Long
    Dim Lastrow As Long
    Lastrow = Range("B" & Rows.Count).End(xlUp).Row
    

    For i = 2 To Lastrow
    
         Range("A" & i).Formula = Join(Application.Index(Range("B" & i & ":CS" & i).Value, 1, 0), """;""")
        
    Next i
    
    End Sub
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
67,955
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
        Range("A" & i).Formula = Range("B" & i) & Chr(34) & Join(Application.Index(Range("c" & i & ":DE" & i).Value, 1, 0), """;""")
 

JoeRooney

Board Regular
Joined
Nov 27, 2017
Messages
132

ADVERTISEMENT

Hi Fluff sorry for the delay on your feedback. Unfortunaltey it is still missing the ; after policy_id

policy_id"trans_process_date";"trans_type";
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
67,955
Office Version
  1. 365
Platform
  1. Windows
I thought you had added that with the other code. If not try
VBA Code:
Range("A" & i).Formula = Range("B" & i) & ";" & Chr(34) & Join(Application.Index(Range("c" & i & ":DE" & i).Value, 1, 0), """;""")
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
67,955
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,856
Messages
5,766,784
Members
425,378
Latest member
kapoor2892

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
Top