Converting and copying specific data

GerrardSVK

New Member
Joined
Sep 18, 2023
Messages
29
Office Version
  1. 2016
Platform
  1. Windows
Dear all,

Can anyone help me?

I got exel where data are stored but I need to change them to be let say "Green".

I need to take data from E2;H9 and make them all to be filled just with max value 0,05.

There is also important to make this data as following

number 0,032 wil mean for me that the final result will be 0,050 x 32% = 0,16
If there will be number higher than 0,1 Mean for 100% there will be randomly generated value between 0,045 and 0,050

I wrote litle macro which should work but I think something is wrong.

I need to launch it from another exel because there is lot of exels than I need to modify like this.

Problem I think is format of copying data because there are data copied from merged rows I am not sure if this is problem.



1707210407994.png


VBA Code:
Sub Makro2()

        Dim KopyRange As String
        KopyRange = Workbooks(1).Sheets(1).Range("B10").Value
            
                
        Workbooks(2).ActiveSheet.Range(KopyRange).Copy
        Workbooks(1).Sheets(2).Range(KopyRange).PasteSpecial
            
        Dim Cell As Range
        
        For Each Cell In Workbooks(1).Sheets(2).Range(KopyRange).Cells
            
            Dim Hodnota As Double
            Hodnota = ActiveCell.Value
            If Hodnota < 0.1 Then
                 GoTo Aplikace
            Else
                 Hodnota = (WorksheetFunction.RandBetween(45, 50) / 1000)
                 GoTo Aplikace
            End If
            
Aplikace:
            Dim Generation As Double
            Generation = Hodnota * 10
            ActiveCell.Offset(0, 10).Select
            ActiveCell.Value = 50 * Generation
            Dim Returned As Double
            Returned = ActiveCell.Value
            ActiveCell.Offset(0, -10).Select
            ActiveCell.Value = Returned
        
        Next
        
        Workbooks(1).Sheets(2).Range(KopyRange).Copy
        Workbooks(2).ActiveSheet.Range(KopyRange).PasteSpecial

End Sub
 

Attachments

  • 1707210382812.png
    1707210382812.png
    43.1 KB · Views: 10

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
If I debug this it Seems that it is performed corectly but stil just in same cell again and again som it is not looping over all cell but stil same cell again why ?

VBA Code:
            Generation = Hodnota * 10
            ActiveCell.Offset(0, 10).Select
            ActiveCell.Value = 0.05 * Generation
            Dim Returned As Single
            Returned = ActiveCell.Value
            ActiveCell.Offset(0, -10).Select
            ActiveCell.Value = Returned
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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