View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default VBA help to output a file

one way (I assume that by "write out to a file" you mean a csv file, and
that the "certain cell" is in column A - adjust as necessary):

Public Sub CopyNonZeroToFile()
Const sFileName As String = "test.csv"
Dim rCrit As Range
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
With ActiveSheet
Set rCrit = .Cells(1, .Columns.Count).End( _
xlToLeft).Offset(0, 2).Resize(2, 1)
rCrit(2).Formula = "=A2<0"
Sheets.Add
.Range("A1").CurrentRegion.AdvancedFilter _
Action:=xlFilterCopy, _
CriteriaRange:=rCrit, _
CopyToRange:=ActiveSheet.Range("A1"), _
Unique:=False
rCrit.Clear
End With
ActiveSheet.Move
With ActiveWorkbook
.SaveAs Filename:=sFileName, _
FileFormat:=xlCSV, _
CreateBackup:=False
.Close SaveChanges:=False
End With
With Application
.DisplayAlerts = True
.ScreenUpdating = True
End With
End Sub

In article ,
Paula Weill wrote:

Hi, I need help in getting the following accomplished and would
appreciate any help you can give:

I have a spreadsheet that I want to write out to a file. In this
spreadsheet if there is a 0 in a certain cell then I don't want that
entire row written to the file but if there is an amount there I want
the entire row written out to the file.

Can anyone help? Thank you so much.

Paula

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!