Don George
Don George

Reputation: 1328

Excel macro is resetting column formats

I am copying some data from Access to Excel, using an Excel macro. It is working fine, except that some of the column formats are being changed in the process. The section of code that fills in the worksheet is

ActiveSheet.UsedRange.Clear
'Add the data (note blank line between headers & data
Cells(Crow + 2, CColumn).CopyFromRecordset RS
'Add the field headers
For Each Item In RS.Fields
    Cells(Crow, CColumn) = Item.Name
    CColumn = CColumn + 1
    Next Item

Which is changing the formats - the Clear command in the 1st line, or the CopyFromRecordset? How do I retain the cell formats?

Upvotes: 0

Views: 143

Answers (1)

JosieP
JosieP

Reputation: 3410

Perhaps use ClearContents instead of Clear

Upvotes: 2

Related Questions