+ Reply to Thread
Results 1 to 7 of 7

How to use row number from user input in formula?

  1. #1
    Registered User
    Join Date
    02-15-2021
    Location
    USA
    MS-Off Ver
    2019
    Posts
    8

    How to use row number from user input in formula?

    To be clear the cell formula is correct I do not need that changed. I am trying to figure out how to insert the row number "P" in to my formula based on the number input by the user so that I do not have to go in and hardcode the number of rows each time I change the data. The code is pulling the data from sheet1 and autofilling the matrix. I am sure there is an easier way to do this but I am trying to learn VBA so its more about the process than the final result for me so please try not to completely change the code if possible.
    Attached Files Attached Files

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: How to use row number from user input in formula?

    Just to be clear - you are talking about ROWS, but P is a COLUMN.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    02-15-2021
    Location
    USA
    MS-Off Ver
    2019
    Posts
    8

    Re: How to use row number from user input in formula?

    P is just the variable I came up with. The coding I have done before on other applications required a variable to be assigned to a user input in this case if the user input 40, P=40. Then where ever P is within the formula would be replaced with 40. If that is not how it works on VBA then that must be where my problem lies

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: How to use row number from user input in formula?

    Not clear about your requirement.
    Formula in B2 then copied across may help.

    =IFERROR(INDEX(Sheet1!$C$2:$C$69,AGGREGATE(15,6,ROW(Sheet1!$C$2:$C$69)/((Sheet1!$A$2:$A$69=$A2)*(Sheet1!$B$2:$B$69=B$1)),1)-ROW($C$1)),"")
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: How to use row number from user input in formula?

    How about
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-15-2021
    Location
    USA
    MS-Off Ver
    2019
    Posts
    8

    Re: How to use row number from user input in formula?

    Quote Originally Posted by Fluff13 View Post
    How about
    Please Login or Register  to view this content.
    This code works. Is there a way to allow the user input to define an autofill range as well? For example if user input is 40, fillRange = Worksheets("Matrix").Range("R2C2:R40C2")

  7. #7
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: How to use row number from user input in formula?

    How about
    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)

Similar Threads

  1. [SOLVED] Having user input and a formula (that can incorporate the user input) in the same cell.
    By Super_Bob in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-21-2018, 05:55 AM
  2. Data Input Form with number of line items based on user input
    By j_gideon in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-25-2013, 02:54 PM
  3. Get input from user using application.inputbox. Input should be number and can be 0
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-11-2013, 11:28 AM
  4. Automatic Formula Input Based on User Input Using a Macro
    By Drayloc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-03-2012, 12:10 PM
  5. Using text box input to lookup number and replace based on user input into new column
    By harl3y412 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-28-2011, 03:15 PM
  6. Multiplying a cell number by a user input number
    By awalsh in forum Excel General
    Replies: 3
    Last Post: 08-26-2010, 09:42 AM
  7. [SOLVED] Requesting user input for a number?
    By StargateFanFromWork in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-20-2006, 12:45 PM

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