PDA

View Full Version : Excel Export



antiga1
11-30-2007, 07:30 AM
Hello!


I want to export some data to a .csv.

It looks like this in Excel:

Column A Column B

Sydney Australien
London England
MAdrid Spanien
Beirut
New Hampshire
Lousville
Conneticut
Boston

The cities in column A are defined as Range("Cities") and those in Column B as Range("Countries").

I can export them but it will look like in excel but I need this in this format in the .csv:

Sydney | London | Madrid | Beirut | New Hampshire |
Australien | England | Spanien | Libanon |

Can anyone help me with the VBA code?

Thanks for your help!!

gnod
11-30-2007, 07:54 AM
maybe this code will give you an idea..


http://vbaexpress.com/kb/getarticle.php?kb_id=759

gnod
11-30-2007, 08:03 AM
or this

http://vbaexpress.com/kb/getarticle.php?kb_id=805

antiga1
11-30-2007, 08:17 AM
@gnod Thanks for your help. But I'm quite a beginner with VBA and I can't find the right solution in the code you showed me.

I only need the parts of my defined range not amoung each other but side by side. And the should be divided by "|"

gnod
11-30-2007, 08:54 AM
I modify this part of code under Module 1 from CustomDelimiterExport Add-In


' loop through range to build text file records
For CountC = 1 To NumC
LineStr = IIf(Leading, Delim, "")
For CountR = 1 To NumR
If Not IsNumeric(rng.Cells(CountR, CountC)) And Not IsDate(rng.Cells(CountR, CountC)) Then
LineStr = LineStr & Qual & rng.Cells(CountR, CountC) & Qual
Else
LineStr = LineStr & rng.Cells(CountR, CountC)
End If
LineStr = LineStr & IIf(CountC < NumR, Delim, "")
Next
'LineStr = LineStr & IIf(Trailing, Delim, "")
ts.WriteLine LineStr
Next

i attach the modifed xla add-in.

thanks matthewpatrick for your code.. :thumb :friends: