Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiply the range using excel VBA

I am using below code to pull data from sheet RawImport to PullData.

Dim lrA As Integer

    lrA = RawImport.Range("B" & Rows.Count).End(xlUp).Row

    PullData.Range("A2:A" & lrA - 6).Value = RawImport.Range("G8:G" & lrA).Value
    PullData.Range("A2:A" & lrA).NumberFormat = "d mmm yyyy h:mm;@"
    PullData.Range("A:A").Columns.AutoFit

    PullData.Range("B2:B" & lrA - 6).Value = RawImport.Range("E8:E" & lrA).Value

    PullData.Range("C2:C" & lrA - 6).Value = RawImport.Range("C8:C" & lrA).Value

    PullData.Range("D2:D" & lrA - 6).Value = RawImport.Range("D8:E" & lrA).Value

    PullData.Range("E2:E" & lrA - 6).Value = RawImport.Range("B8:B" & lrA).Value

    PullData.Range("F2:F" & lrA - 6).Value = RawImport.Range("F8:F" & lrA).Value

    Application.Calculation = xlCalculationAutomatic

    Application.ScreenUpdating = True

Now I would like to multiply E and F column (from Row 2 onwards) and add the result to G column. I tried to add below code along with above

PullData.Range("G2:G" & lrA - 6).Value = PullData.Range("F2:F" & lrA - 6).Value * PullData.Range("E2:E" & lrA - 6).Value

But I am getting Type Mismatch error while running the code. What will be the best way to multiply the values and assign to G column?

like image 674
acr Avatar asked Dec 02 '25 07:12

acr


1 Answers

Write a quick formula and resolve to the formula results.

PullData.Range("G2:G" & lrA - 6).Formula = "=F2*E2"
PullData.Range("G2:G" & lrA - 6) = PullData.Range("G2:G" & lrA - 6).Value

If you don't want to write the formula, create an array and loop through it storing the results from individual row multiplication operations.