I'm new to macros. I created a very simple macro which allows a range of cells to be formatted within a worksheet. The macro works fine within the worksheet however when I save the document as a csv file there are several trailing commas. I know that the trailing commas are a result of formatting that occurred with the empty values of the worksheet. I need the macro to only format the cells that contain data, but I also need to keep the range of cells. Is this possible? I've tried conditional formatting, CountA formulas, IsEmpty macros,and Is/Then/Else macros but nothing seems to work. I included an example of the data that I have been working with, any help will be appreciated.
Sub FormatDollarAmount()
Set MyCellRange = Range("F2:F51")
If (Not (IsEmpty("F2:F51"))) Then
Range("F2:F51").NumberFormat = "#,##0.00;_(@_)"
Else
End If
End Sub