Macro variable help

 nimesh -

I have declared a variable

Dim x As String
x = Cells(x + 10, 10).Value

I am getting the value of a cell in x. I want to use that value in a sumif function which i have defined below

Cells(y,6).Formula = "=SUMIF(I25:I1000,& x &,F25:F1000)"

y is defined somewhere else so that is not a problem.

I keep getting a error here, how do i pass variable inside a sumif function.

Thanks for all your help

1 reply

Looks like you need to add two more quotation marks.

Try this:

Cells(y,6).Formula = "=SUMIF(I25:I1000," & x & ",F25:F1000)"
Thanks for your help, it worked but gave me a small problem. In the sumif function it got the exact value from the cell in excel but without the quotes "" in the sumif formulae due to which the sumif function returns a 0. How do i fix that.

Thanks for ur help