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
 
Hi

Opening this query back up, would it be possible to add a condition to the above code that if the cell is blank no quotation marks are required

Example:

2 blank cells are currently reported as "";"";

with the new condition only the separator should be reported so two blank cells would be reported as ;; instead.
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
How about
VBA Code:
Range("A" & i).Formula = Range("B" & i) & ";" & Chr(34) & Replace(Join(Application.Index(Range("c" & i & ":DE" & i).Value, 1, 0), """;"""), """""", "")
 
Upvote 0
Solution

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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