1

With vb.net I would like to select 4 cells in Excel and then pass those cell values along with 1 button tag to a formula in Excel.

I press a button with a month, say "May" as text. I want to grab a cell in Excel labeled "May1t" the value of which is the number of hours until may. This is the code I'm using.

xlsWB.Worksheets(2).Range(Month1 & "1t").Value

I am able to set a variable with this as the value but,

I want to pass this cell (which will be updating as the time counts down) and 3 other similarly specified cells along with the button tag to an Excel formula.

I have something like this:

Private Sub F_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles F.Click

    xlsWB.Worksheets(4).Range("B2").Formula = "=MyFunction()"
    xlsWB.Worksheets(1).Range(Month1 & "1t").Select()

End Sub

The formula takes the parameters in the order: MyFunction(Cell,Tag,Cell,Cell,Cell).

1 Answer 1

0

Assuming Cell & Tag are strings, can you just go?:

xlsWB.Worksheets(4).Range("B2").Formula =
"=MyFunction(" & Cell & "," & Tag & "," & Cell & "," & Cell & "," & Cell & ")"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.