Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
bretweir,
How about code to write a CSV? Select your range, and run the code below. HTH, Bernie MS Excel MVP Sub ExportToCSV() Dim FName As String Dim WholeLine As String Dim FNum As Integer Dim RowNdx As Long Dim ColNdx As Integer Dim StartRow As Long Dim EndRow As Long Dim StartCol As Integer Dim EndCol As Integer 'Change the folder path here - will create a dated-name csv file FName = "C:\Excel\CSV" & Format(Now(), " yyyy mmm dd") & ".csv" Application.ScreenUpdating = False On Error GoTo EndMacro: FNum = FreeFile With Selection StartRow = .Cells(1).Row StartCol = .Cells(1).Column EndRow = .Cells(.Cells.Count).Row EndCol = .Cells(.Cells.Count).Column End With Open FName For Output Access Write As #FNum For RowNdx = StartRow To EndRow WholeLine = "" For ColNdx = StartCol To EndCol If WholeLine = "" Then WholeLine = Cells(RowNdx, ColNdx).Text Else WholeLine = WholeLine & "," & Cells(RowNdx, ColNdx).Text End If Next ColNdx Print #FNum, WholeLine Next RowNdx EndMacro: On Error GoTo 0 Application.ScreenUpdating = True Close #FNum End Sub "bretweir " wrote in message ... This may be posted somewhere in this HUGE forum, but I couldn't find it. I want to create a macro that selects a range of my choosing, copies it (or just puts it) to a text file of my choosing. This will be a sort of data archiving for an ever changing spreadsheet. Thanks in advance for any help. --- Message posted from http://www.ExcelForum.com/ |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
importing text file data into excel | Excel Discussion (Misc queries) | |||
Rows of Data in Excel to Text File | Excel Discussion (Misc queries) | |||
importing text file, removing data and outputting new text file | Excel Programming | |||
Open delimited text file to excel without changing data in that file | Excel Programming | |||
Adding Data from EXCEL to a TEXT file | Excel Programming |