I am trying to multiply a range by the result of an input box

时间:2016-04-15 11:12:54

标签: excel vba

I have taken a copy of a worksheet in my work book and want to model the figures in a certain column by a variable rate. My code is as follows.

Sub Inflate_Expense()

    Dim Rate As Integer
    Dim rngData As Range

get_Rate:
    Rate = Application.InputBox("Enter the rate", , , , , , , 1)

        Set rngData = ThisWorkbook.Worksheets("Sheet1").Range("K103:K256")
            rngData = Evaluate(rngData.Address & "*Rate")

End Sub

What happens is the values in my worksheet result in #NAME?, which im guessing is because it is trying to multiply "*Rate" as a string and is not using "Rate" as the result of the input box.

I know the code works if i replace Rate with number ie:

 Set rngData = ThisWorkbook.Worksheets("Sheet1").Range("K103:K256")
            rngData = Evaluate(rngData.Address & "*1.02")

What I'm having difficulty with is replacing

 Evaluate(rngData.Address & "*Rate") 

To match the input box result.

1 个答案:

答案 0 :(得分:0)

Sub Inflate_Expense()

Dim Rate As Variant
Dim rngData As Range

get_Rate:
    Rate = Application.InputBox("Enter the rate", , , , , , , 1)

        Set rngData = ThisWorkbook.Worksheets("Sheet1").Range("K103:K256")
            rngData = Evaluate(rngData.Address & "*" & Rate)

End Sub