Thread: keep formatting
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
ryguy7272 ryguy7272 is offline
external usenet poster
 
Posts: 2,836
Default keep formatting

I think PasteSpecial will do that for you. Try this snippet of code:

'Select your data to copy...
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

Make sure you have a backup of your date...in case the code does something
you do NOT want.

Regards,
Ryan---

--
RyGuy


"Striker" wrote:

I am copying a large range, nealy 60K rows. One of the colums has a 15 digit
number in it. The destination cell is pre-formatted as text, and I want to
keep it that way. However when I copy the range from the CSV file to the
template, the formatting goes with it. Code below, how can I maintain the
formatting I have in the destination sheet?

Dim iLastRow As Long
Dim sFile1 As String
Dim wb, wkbkCSV As Workbook
Dim rDestCell As Range

sFile1 = Application.GetOpenFilename("CSV Files, *.csv")
If sFile1 = "False" Then
Exit Sub
End If

Set rDestCell = Workbooks("Sessions.xlsm").Worksheets("Sheet1").Ra nge("A2")
Set wkbkCSV = Workbooks.Open(Filename:=sFile1)

With wkbkCSV
.Worksheets(1).UsedRange.Copy Destination:=rDestCell
.Close savechanges:=False
End With