VBA RoundUp while copying and pasting

avd88

Board Regular
Joined
Jan 18, 2016
Messages
112
Hello,

Trying to roundUp to a whole number while copying and pasting some data. The data being copied that needs to be rounded up is the one marked in the code. Tried using the worksheet function in different ways but can't figure it out. Help is appreciated!:

VBA Code:
Sub CurveFiller()
 Dim i As Integer
 Dim lastrow As Integer
 
 lastrow = Sheets("1").Cells(Rows.Count, 1).End(xlUp).Row
 
 For i = 2 To lastrow
    Sheets("1").Cells(i, 1).Copy
    Sheets("2").Range("B5").PasteSpecial xlPasteValues
    Sheets("2").Range("C5").PasteSpecial xlPasteValues
    Sheets("2").Range("G38").Copy  <------------ NEED ROUNDED UP
    Sheets("1").Cells(i, 2).PasteSpecial xlPasteValues
    Sheets("2").Range("i38").Copy   <------------ NEED ROUNDED UP
    Sheets("1").Cells(i, 3).PasteSpecial xlPasteValues

 Next i

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Why does the roundup need to be part of the copy? Why not round the value after you paste it? Example (not tested):

VBA Code:
Sub CurveFiller()
    Dim i As Integer
    Dim lastrow As Integer
    
    lastrow = Sheets("1").Cells(Rows.count, 1).End(xlUp).Row
    
    For i = 2 To lastrow
        Sheets("1").Cells(i, 1).Copy
        Sheets("2").Range("B5").PasteSpecial xlPasteValues
        Sheets("2").Range("C5").PasteSpecial xlPasteValues
        
        Sheets("2").Range("G38").Copy  '<------------ NEED ROUNDED UP
        With Sheets("1").Cells(i, 2)
            .PasteSpecial xlPasteValues
            .Value = Application.WorksheetFunction.RoundUp(.Value, 0)
        End With
        
        Sheets("2").Range("i38").Copy   '<------------ NEED ROUNDED UP
        With Sheets("1").Cells(i, 3)
            .PasteSpecial xlPasteValues
            .Value = Application.WorksheetFunction.RoundUp(.Value, 0)
        End With
    Next i
    
End Sub
 
Upvote 0
Solution
Thanks for your reply! It didn't have to be in the copy or paste part. I wasn't sure how to implement it properly and this worked for what I needed. Thank you!!!
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,906
Members
449,132
Latest member
Rosie14

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