Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Create a User defined VBA Function that calculates the rate of diffusion (dif

ID: 3724997 • Letter: 1

Question

1. Create a User defined VBA Function that calculates the rate of diffusion (diffusivity) of nd Carbon in Iron (Fe). Make sure that the function is in a module. See page 2 for eq values. 2. Input the values of Temperature from 50 C to 1200 -C in steps of 50 degrees on the spreadsheet. Note the temperature in the calculation is in Kelvin. 3. Write a VBA sub routine that will calculate the values of the rate of Diffusion (Diffusivity) for both the alpha and gamma iron (Fe) and write the rate of Diffusion to the spreadsheet. values for Diffusivity will be on the order of e-27-e-05) Use the user defined function from part 1 (above) to calculate diffusivity in the sub routine. Use only one user defined function for both alpha and gamma Fe. Use in your subroutine: a. b. for i-1 to n where n is the number of temperature values next i · Offset commands to move around the spreadsheet. (do not use arrays) The program must calculate the diffusivity for all values of temperature for both Alpha and Gamma Fe. Convert to Kelvin in the sub program. Temperature Celsius Diffusivity Alpha Fe Gamma Fe Kelvin 100 200 300 350 400 450 500 550 650 700 750 800 850 900 950 1000 1050 1100 1150 1200

Explanation / Answer

Screenshot:-

------------------------------------------------------------------------------------------------------------------------------------------------------------------

VBA Code:-

'Sub routine for getting alpha and gamma diffusion value in excel
Sub rateOfDiffusion()
    Dim iRow As Integer 'variable for looping
    iRow = 26
   'Loop to go through each raw
    For i = 3 To iRow
        Range("B" & i).Value = Range("A" & i).Value + 273.15 'Celcuis to kelvin conversion
        Range("B" & i).Offset(0, 2).Value = diffusivity(0.0062, 80000, 8.314, Range("B" & i).Value) 'call function diffusivity for alpha calculation
        Range("B" & i).Offset(0, 3).Value = diffusivity(0.23, 148000, 8.314, Range("B" & i).Value) 'call function diffusivity for alpha calculation
    Next i
End Sub

----------------------------------------------------------------------------------------------------------------------
'Function defenition for diffusivity calculation
Function diffusivity(ByVal dCoeff As Double, ByVal Q As Double, R As Double, ByVal T As Integer)
    diffusivity = dCoeff * Exp(-Q / (R * T))
End Function