Import data to another sheet without formatting

sofas

Well-known Member
Joined
Sep 11, 2022
Messages
559
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
Hello, how can I do the same thing, but without copying formats. Copy values only



VBA Code:
Sub copy_test()

Dim c As Range, lr As Long, dl As Long
Dim cDest As Range, Réf As Range, Rng As Range

Dim WSdata As Worksheet: Set WSdata = Worksheets("Ordre")
Dim WSdest As Worksheet: Set WSdest = Worksheets("PL")
Set Réf = WSdata.Range("o2")

dl = WSdata.Cells(WSdata.Rows.Count, 1).End(xlUp).Row
lr = WSdest.Cells(Rows.Count, "a").End(xlUp).Row

Set Rng = WSdata.Range("a2:a" & dl).Find(What:=Réf, LookIn:=xlValues, LookAt:=xlWhole)
If Not Rng Is Nothing Then
WSdest.Range("a2:m" & lr).ClearContents
WSdata.Rows(1).Copy WSdest.Rows(1)
Set cDest = WSdest.Range("a2:m2")
Application.ScreenUpdating = False
For Each c In WSdata.Range("a2:a" & WSdata.Cells(Rows.Count, "a").End(xlUp).Row).Cells
    If Not IsError(Application.Match(c.Value, Réf, 0)) Then
        With WSdata
            .Range(.Cells(c.Row, "a"), .Cells(c.Row, "m")).Copy cDest
        End With
        Set cDest = cDest.Offset(1)
    End If
Next c
Else
 MsgBox "unavailable!!"
End If
Application.ScreenUpdating = True


End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Replace your Copy line with these two lines
VBA Code:
            .Range(.Cells(c.Row, "a"), .Cells(c.Row, "m")).Copy
            cDest.PasteSpecial Paste:=xlPasteValues
 
Upvote 0
Solution

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top