Jump to content

Returning a method's value c# error 'keyword followed by void'

I've created a method which selects all the cells in Excel beginning with a1 and ending when there are no more columns or rows.  When a button is clicked, I then want to initiate this so that it selects them, however I am getting an error that I can't return the value.  This is what I have:       

        public void selectAllCells(Worksheet activeSheet)
        {
            activeSheet.get_Range("a1").EntireRow.EntireColumn.Select();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            return selectAllCells;
        }

How do I go about returning the method when the button is clicked.

Link to comment
Share on other sites

Link to post
Share on other sites

The selectAllCells is a method and not a variable or object.  In order to trigger the selectAllCells method you'll need to execute it.

 

public void selectAllCells(Worksheet activeSheet)
{
activeSheet.get_Range("a1").EntireRow.EntireColumn.Select();
}

private void button1_Click(object sender, EventArgs e)
{
	// I think this may be right, if not try removing the this.
	this.selectAllCells();
}

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, Ceff said:

The selectAllCells is a method and not a variable or object.  In order to trigger the selectAllCells method you'll need to execute it.

 


public void selectAllCells(Worksheet activeSheet)
{
activeSheet.get_Range("a1").EntireRow.EntireColumn.Select();
}

private void button1_Click(object sender, EventArgs e)
{
	// I think this may be right, if not try removing the this.
	this.selectAllCells();
}

 

that's only going to call it you are at assigning it to anything.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

On 27/01/2017 at 10:15 PM, vorticalbox said:

that's only going to call it you are at assigning it to anything.

I'm trying to assign the 

activeSheet.get_Range("a1").EntireRow.EntireColumn.Select();

so that when button1 is clicked, it will run that piece of code.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×