+ Reply to Thread
Results 1 to 3 of 3

Running a WorksheetFunction on a Range of Cells and returning results in 2nd Range

  1. #1
    Forum Contributor
    Join Date
    06-28-2010
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    101

    Running a WorksheetFunction on a Range of Cells and returning results in 2nd Range

    Like the title says, I have a set of numbers in A1:A5 and I want to be able to press a button and run a formula (power in this case) on each cell and return the results in B1:B5.

    So it would look like this:

    A B
    2 4
    3 9
    3 9
    5 25
    2 4

    I am very much a begginer when it comes to macros, but I am trying to learn my way through them. I could do single value things fine (and I know I can do all this through functions in Excel but I want to know how to do it as a macro)

    Here is my current code:

    Sub Button1_Click()

    Range("B1:B5").Value = Application.WorksheetFunction.Power(Range("A1:A5"), 2)

    End Sub


    Thanks!

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,065

    Re: Running a WorksheetFunction on a Range of Cells and returning results in 2nd Range

    Try this

    Please Login or Register  to view this content.
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Running a WorksheetFunction on a Range of Cells and returning results in 2nd Range

    There is often more than one way to do things in VBA. Here are two methods to do what you ask.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1