How to copy a value with this code and get the right value

Romano_odK

Active Member
Joined
Jun 4, 2020
Messages
379
Office Version
  1. 365
Platform
  1. Windows
Good morning,
I am using this code to copy values from one column to another which fine by itself. Now I running to the problem that I want to copy a column with as value a number to a column that are percentages. This results in huge percentages. Is there a way to fix this.

VBA Code:
Private Sub UpdateKorting_Click()
With Sheets("Items").ListObjects("ItemsImport")
   .ListColumns(81).DataBodyRange.Copy
   .ListColumns(50).DataBodyRange.PasteSpecial xlPasteValues, , True
   Application.CutCopyMode = False
Range("AX6").Activate
ActiveWindow.ScrollRow = 6
End With
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.
here are a couple ways. If you can have formulas use #2

VBA Code:
Private Sub UpdateKorting_Click()
    Dim ar As Variant
    Dim i As Long
    
    Application.ScreenUpdating = False
    With Sheets("Items").ListObjects("ItemsImport")
       ar = .ListColumns(1).DataBodyRange.Value  ' change your column #
       .ListColumns(2).DataBodyRange.NumberFormat = "0.00%"  '  change your column #
       For i = 1 To UBound(ar)
        ar(i, 1) = ar(i, 1) / 100
       Next
       .ListColumns(2).DataBodyRange.Value = ar  ' change your column #
    End With
    Application.ScreenUpdating = True
End Sub

Private Sub UpdateKorting_Click2()
    Application.ScreenUpdating = False
    With Sheets("Items").ListObjects("ItemsImport")
       .ListColumns(2).DataBodyRange.NumberFormat = "0.00%" ' change your column #
       .ListColumns(2).DataBodyRange.Formula = "=[@col1]/100" ' name of your column &  change your column #
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
here are a couple ways. If you can have formulas use #2

VBA Code:
Private Sub UpdateKorting_Click()
    Dim ar As Variant
    Dim i As Long
   
    Application.ScreenUpdating = False
    With Sheets("Items").ListObjects("ItemsImport")
       ar = .ListColumns(1).DataBodyRange.Value  ' change your column #
       .ListColumns(2).DataBodyRange.NumberFormat = "0.00%"  '  change your column #
       For i = 1 To UBound(ar)
        ar(i, 1) = ar(i, 1) / 100
       Next
       .ListColumns(2).DataBodyRange.Value = ar  ' change your column #
    End With
    Application.ScreenUpdating = True
End Sub

Private Sub UpdateKorting_Click2()
    Application.ScreenUpdating = False
    With Sheets("Items").ListObjects("ItemsImport")
       .ListColumns(2).DataBodyRange.NumberFormat = "0.00%" ' change your column #
       .ListColumns(2).DataBodyRange.Formula = "=[@col1]/100" ' name of your column &  change your column #
    End With
    Application.ScreenUpdating = True
End Sub
Thank yoy, this works great.
 
Upvote 0

Forum statistics

Threads
1,215,984
Messages
6,128,110
Members
449,421
Latest member
AussieHobbo

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