Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Macro Help

Status
Not open for further replies.

CoolDudeeh

IS-IT--Management
Oct 21, 2003
21
US
Ok ..... here is my situation.
I have an excel spreadsheet with data in it from A1-X700
I found the below macro to put out the cells with " around the data in each cell.
The below macro works great ...... but I would like to modify it not to put " around data in certain columns.
For example I want "around" each cells info except say column D and N.
Can anyone help me?

Public Sub OutputQuotedCSV()
Const QSTR As String = """"
Dim myRecord As Range
Dim myField As Range
Dim nFileNum As Long
Dim sOut As String

nFileNum = FreeFile
Open "file.txt" For Output As #nFileNum
For Each myRecord In Range("A2:A723")
With myRecord
For Each myField In Range(.Cells(1), _
Cells(.Row, 256).End(xlToLeft))
sOut = sOut & " " & QSTR & _
Replace(myField.Text, QSTR, QSTR & QSTR) & QSTR
Next myField
Print #nFileNum, Mid(sOut, 2)
sOut = Empty
End With
Next myRecord
Close #nFileNum
End Sub
 


Hi,

in your for...next
Code:
    For Each myField In Range(.Cells(1), _
                Cells(.Row, 256).End(xlToLeft))
        Select Case myField.Column
            Case Cells(1, "D").Column, Cells(1, "N").Column
                'no op
            Case Else
                sOut = sOut & " " & QSTR & _
                    Replace(myField.Text, QSTR, QSTR & QSTR) & QSTR
        End Select
    Next myField

Skip,
[sub]
[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue][/sub]
 
Skip, shouldn't the 'no op be ?
sOut = sOut & " " & myField.Txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

For example I want "around" each cells info except say column D and N.
emphasis mine

Skip,
[sub]
[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue][/sub]
 


Oh, yes. [blush]

I neglected to see that he's reading in a text file.



Skip,
[sub]
[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue][/sub]
 
Thank you skip and PH!!!!!
Worked like a charm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top