use a foor loop for range of cells to find there percentage of a number

Viewed 27

In my excel VBA code bellow I take a cell which is in cell b5 and find its percentage of total of the number in cell b1. This operation takes place in line

.Range("B6").Value = 100 - ((operationOne / StartingTotal) * 100)

. This works but in only one cell. I would like it to extend to what ever has a number in cells in a range from b2 : d2 we find out the percentage as it relates to the cell in d1. This operation can be completed I assume using a for loop.

sample

Sub Preform_Subtraction_Verion1()
    
    
    Dim operationOne As Double
    Dim DayTotal4 As Double
    Dim CalcWS As Worksheet
    Dim StartingTotal As Double
          
    Set CalcWS = ThisWorkbook.Worksheets("Sheet1")
    
    With CalcWS
    
    
        StartingTotal = .Range("D1").Value
        
        
        
        operationOne = StartingTotal - .Range("B5").Value
        
        
        .Range("B6").Value = 100 - ((operationOne / StartingTotal) * 100)
        
        
        
        
    End With
    
End Sub
0 Answers
Related