Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hello John Paul, From your last post it looks like you want to test the cell first before concatenating the contents. The function of Data = Left(Data, Len(Data) - 1 is to remove the final comma from the concatenated string before it is written into the file. Here is code with the corrections ... Code: -------------------- Sub SaveCSV() Dim ColMax As Long Dim Data Dim DataFile As String Dim FF As Integer Dim FirstRow As Long Dim I As Long Dim J As Long Dim LastCol As Long Dim LastRow As Long FF = FreeFile DataFile = "C:\CSVData.txt" With ActiveSheet.UsedRange FirstRow = .Row LastRow = .Rows.Count + X + 1 End With ColMax = ActiveSheet.Columns.Count Open DataFile For Output As #FF For I = FirstRow To LastRow Data = "" LastCol = Cells(I, ColMax).End(xlToLeft).Column For J = 1 To LastCol If Mid(Cells(I, J).Value, 1) = "c" Then Data = Data & Cells(I, J).Value & "," End If Next J If Data < "" Then Data = Left(Data, Len(Data) - 1) Write #FF, Data End If Next I Close #FF End Sub -------------------- Sincerely, Leith Ross -- Leith Ross ------------------------------------------------------------------------ Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465 View this thread: http://www.excelforum.com/showthread...hreadid=480356 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
looping through rows and columns | Excel Discussion (Misc queries) | |||
looping across columns in range? | Excel Discussion (Misc queries) | |||
Looping thru columns | Excel Programming | |||
Looping through columns | Excel Programming | |||
Looping thru columns beyond Z | Excel Programming |