?
Solved

MS Excel - Copy data range without existing formatting.

Posted on 2014-02-04
4
Medium Priority
?
389 Views
Last Modified: 2014-02-04
In my vb.net application, I create a new worksheet in an existing Excel workbook by transferring data from an MS Access query.

With the following code (thanks again Harry Lee!), a range is selected in the new worksheet then copied to a different range in an old worksheet in the same workbook:

Dim NewWS As Worksheet, OldWS As Worksheet, NewRng As Range, OldLastRW As Long
NewWS = objExcel.Sheets("NewData")
OldWS = objExcel.Sheets("OldData")
OldLastRW = OldWS.Cells(OldWS.Rows.Count, 1).End(XlDirection.xlUp).Row
NewRng = NewWS.Range(NewWS.Cells(2, 1), NewWS.Cells(NewWS.Cells _(NewWS.Rows.Count, 1).End(XlDirection.xlUp).Row, 12))
NewRng.Copy(OldWS.Cells(OldLastRW + 2, 1))

All works well, but when the new worksheet was initially created from the Access query, the cells with data in them have borders which I do not want copied to the new worksheet.

What can I add/modify in the above code to prevent any formatting being copied with the data?
0
Comment
Question by:Tim313
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 15

Accepted Solution

by:
unknown_routine earned 2000 total points
ID: 39833311
You can clear formats after copying:


For example

Range("C2:E4").Select
Selection.ClearFormats


So each time after you copy to destination, select the destination and then clear formats.
0
 
LVL 23

Expert Comment

by:Ejgil Hedegaard
ID: 39833412
If you have formulas to be copied with the range then the method from unknown_routine is the easiest way, but you say it is a table so probably you only need to copy values.

After copy (your last line) select the destination sheet and the upper left cell where you want the result, then insert the values with
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39833495
Although this question is asked in the excel zone, the more appropriate zone would be vb.net

I have not worked on vb.net but this works in VBA

OldWS.Cells(OldLastRW + 2, 1).resize(NewRng.rows,NewRng.columns).value=NewRng.value
0
 

Author Closing Comment

by:Tim313
ID: 39834296
To all, thanks for your suggestions.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question