Export to CSV values

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

Hi
Having trouble with code to do the following.
Worksheet has data in columns A to F and rows 1 to 42.
I wish to export to CSV file all the rows except rows with the numeric value
0 in column F

I have done some VBA programing but not for a while so having trouble
getting started.

Any help would be greatfully accepted
Thanks
Neil
 
D

Dave Peterson

I would record a macro when I applied Data|filter|autofilter (add headers if you
have to).

Show the 0's in column A.
Select those visible rows
F5 (or ctrl-g or edit|goto)|special|visible cells only

And paste into a new worksheet in a new workbook.

Then save that new workbook as a .csv file

Close (without saving) that new workbook.
 
M

msnews.microsoft.com

Thanks Dave
Really looking for code to run from the click method on a button object.
The user (My wife) needs a 1 click solution as she has to do several of
these every week.
Cheers
Neil
 
M

msnews.microsoft.com

Thanks for your help Dave
You seem to give a lot of help to others.
Your idea was a good one however I got off my butt and wrote the following
code.

Private Sub CommandButton2_Click()
Dim Check, Counter, Myfile
Myfile = Cells(1, 8) ' name of file to export
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(Myfile, True)
Check = True: Counter = 0 ' Initialize variables.

Do ' Outer loop.
Do While Counter < 43 ' Inner loop.
Counter = Counter + 1 ' Increment Counter.
If Counter <= 42 Then 'If condition is True.

If Cells(Counter, 6) > 0 Then
a.WriteLine (Cells(Counter, 7))
'=CONCATENATE(TEXT(A1,"dd/mm/yy"),",",B1,",",C1,",",D1,",",E1,",",F1)
End If

Else

Check = False ' Set value of flag to False.
a.Close ' flush the buffer and close the file.
End If
Exit Do
Loop
Loop Until Check = False ' Exit outer loop immediately.

End Sub

Thanks again
Neil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top