Convert excel to CSV format using a join

JoeRooney

Board Regular
Joined
Nov 27, 2017
Messages
169
Office Version
  1. 365
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

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
How about
VBA Code:
        Range("A" & i).Formula = Join(Application.Index(Range("B" & i & ":DE" & i).Value, 1, 0), """;""")
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
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
 
Upvote 0
How about
VBA Code:
        Range("A" & i).Formula = Range("B" & i) & Chr(34) & Join(Application.Index(Range("c" & i & ":DE" & i).Value, 1, 0), """;""")
 
Upvote 0
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";
 
Upvote 0
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), """;""")
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,894
Messages
6,122,124
Members
449,066
Latest member
Andyg666

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