snt
snt

Reputation: 35

Multiply Cell range by textbox value input

I'm trying to multiply a range of cells by the value of a textbox that the user inputs. My code keeps giving me a Type Mismatch error. How should I change my code?

Sub CommandButton2_Click()
    Dim cell As Range
    For Each cell In Range("F2:F25")
        cell.Formula = TextBox2.Value * Range("E2:E25").Value
    Next cell
End Sub

Upvotes: 1

Views: 121

Answers (1)

BigBen
BigBen

Reputation: 49998

Range("E2:E25").Value is a 2D array.

If you want to successively multiply F2, F3, F4 by E2, E3, E4, then use Offset as you loop:

cell.Value = TextBox2.Value * cell.Offset(,-1).Value

Upvotes: 1

Related Questions