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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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