VBA copy and paste as values

djossh

Board Regular
Joined
Jul 27, 2009
Messages
243
Hi.. the code below are working fine except that I need to have it in values not in formula. can anyone help..Thanks


hereis my code:

Private Sub okbut_Click()


Dim startdate As Date, enddate As Date
Dim rng As Range, destRow As Long
Dim shtSrc As Worksheet, shtDest As Worksheet
Dim c As Range


Set shtSrc = Sheets("SUMMARY")
Set shtDest = Sheets("Transmittal")


destRow = 20 'start copying to this row


startdate = TRANSMIT.transfrom.Value
enddate = TRANSMIT.transto.Value


'don't scan the entire column...
Set rng = Application.Intersect(shtSrc.Range("D:D"), shtSrc.UsedRange)


For Each c In rng.Cells
If c.Value >= startdate And c.Value <= enddate Then

c.Offset(0, 0).Resize(1, 1).Copy shtDest.Cells(destRow, 1)
c.Offset(0, 1).Resize(1, 1).Copy shtDest.Cells(destRow, 2)
c.Offset(0, -2).Resize(1, 1).Copy shtDest.Cells(destRow, 3)
c.Offset(0, -1).Resize(1, 1).Copy shtDest.Cells(destRow, 4)
c.Offset(0, 4).Resize(1, 1).Copy shtDest.Cells(destRow, 5)
c.Offset(0, 11).Resize(1, 1).Copy shtDest.Cells(destRow, 6)

destRow = destRow + 1


End If
Next




End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hello Djossh,

Try changing this block of code:-

Code:
c.Offset(0, 0).Resize(1, 1).Copy shtDest.Cells(destRow, 1)
            c.Offset(0, 1).Resize(1, 1).Copy shtDest.Cells(destRow, 2)
            c.Offset(0, -2).Resize(1, 1).Copy shtDest.Cells(destRow, 3)
            c.Offset(0, -1).Resize(1, 1).Copy shtDest.Cells(destRow, 4)
            c.Offset(0, 4).Resize(1, 1).Copy shtDest.Cells(destRow, 5)
            c.Offset(0, 11).Resize(1, 1).Copy shtDest.Cells(destRow, 6)

to

Code:
c.Offset(0, 0).Resize(1, 1).Copy
shtDest.Cells(destRow, 1).PasteSpecial xlValues

c.Offset(0, 1).Resize(1, 1).Copy
shtDest.Cells(destRow, 2).PasteSpecial xlValues

c.Offset(0, -2).Resize(1, 1).Copy
shtDest.Cells(destRow, 3).PasteSpecial xlValues

c.Offset(0, -1).Resize(1, 1).Copy
shtDest.Cells(destRow, 4).PasteSpecial xlValues

c.Offset(0, 4).Resize(1, 1).Copy
shtDest.Cells(destRow, 5).PasteSpecial xlValues

c.Offset(0, 11).Resize(1, 1).Copy
shtDest.Cells(destRow, 6).PasteSpecial xlValues

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
.
Untested here ... see if this works :

Code:
shtDest.Cells(destRow, 1).value = c.Offset(0, 0).Resize(1, 1).value
shtDest.Cells(destRow, 2).value = c.Offset(0, 1).Resize(1, 1).value
shtDest.Cells(destRow, 3) = c.Offset(0, -2).Resize(1, 1).value
shtDest.Cells(destRow, 4) = c.Offset(0, -1).Resize(1, 1).value
shtDest.Cells(destRow, 5) = c.Offset(0, 4).Resize(1, 1).value
shtDest.Cells(destRow, 6) = c.Offset(0, 11).Resize(1, 1).value

Of course you'll still need the code previous to and following the above suggested change.
 
Upvote 0
You're welcome djossh. I'm glad that we were able to help.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,370
Members
449,080
Latest member
Armadillos

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