Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here is a cut down version of your code.
Declaring MyValue As String ensures that Excel does the necessar conversions automatically. You may wish to change the date format check etc. to something mor appropriate. '--------------------------------------------------- Sub ADD_TO_TEXTFILE2() Dim FileNum As Integer Dim MyFormat As String Dim MyValue As String ' ensures text conversion Dim ColumnCount As Integer Dim RowCount As Long Dim NumRows As Long Dim NumCols As Long '-------------------------- FileNum = FreeFile() Open "C:\test.txt" For Append As #FileNum '----------------------------------- NumRows = Selection.Rows.Count NumCols = Selection.Columns.Count For RowCount = 1 To NumRows For ColumnCount = 1 To NumCols MyValue = _ Selection.Cells(RowCount, ColumnCount) MyFormat = _ Selection.Cells(RowCount, ColumnCount).NumberFormat '- check for date format If InStr(1, MyFormat, "-") = 0 _ And InStr(1, MyFormat, "/") = 0 Then MyValue = """" & MyValue & """" End If Print #FileNum, MyValue; If ColumnCount < NumCols Then Print #FileNum, ","; End If Next Print #FileNum, Next '---------------------------------- Close #FileNum End Sub '-- eop --------------------------------------- -- Message posted from http://www.ExcelForum.com |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort | Excel Worksheet Functions | |||
My excel macro recorder no longer shows up when recording macro | Excel Discussion (Misc queries) | |||
My excel macro recorder no longer shows up when recording macro | Excel Discussion (Misc queries) | |||
Launch Macro in Access via Macro running in Excel??? | Excel Programming |