Input Box in Formula

depawl52

New Member
Joined
Dec 27, 2021
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
I have an excel program that does various calculations running in a macro.
As per the attached there is a data sheet (Sheet 1 on the left) and a calculations sheet (Sheet 2 on the right)
The example I've shown is a very simplified version of what I need to accomplish.
The formula is Cell B4, Sheet 2 is:
=INDEX(Sheet1!$B4:$G4,,RIGHT(B$1,FIND("_",B$1)-1))
Right now the cell range in the calculation is hard coded in the macro, but what I'm looking for is an Input Box (or something similar)
where my end users can enter a cell range from Sheet 1, which would then be inserted into the formula.
So in the example, users would enter:
Sheet1!$B4:$G5
in the Input Box.
I need to have this capability as the number of columns and rows in the data on Sheet 1 varies constantly.
I've been trying for days to get something to work but no success.
Anything to point me in the right direction would be most appreciated.
Thank you.
 

Attachments

  • Sheet1.jpg
    Sheet1.jpg
    45 KB · Views: 11
  • Sheet2.jpg
    Sheet2.jpg
    50.3 KB · Views: 11

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Welcome to the Board!

I was just looking back to some post made on days that I was away, and came across yours.
Is this something like what you are looking for?
VBA Code:
Sub MyMacro()

    Dim rng As String
    
'   Prompt user for range
    rng = InputBox("What range do you wish to insert?")
    
'   Insert formula on sheet 2
    Sheets("Sheet2").Range("B4").Formula = "=INDEX(" & rng & ",,RIGHT(B$1,FIND(""_"",B$1)-1))"
    
End Sub
 
Upvote 0
Solution
Welcome to the Board!

I was just looking back to some post made on days that I was away, and came across yours.
Is this something like what you are looking for?
VBA Code:
Sub MyMacro()

    Dim rng As String
   
'   Prompt user for range
    rng = InputBox("What range do you wish to insert?")
   
'   Insert formula on sheet 2
    Sheets("Sheet2").Range("B4").Formula = "=INDEX(" & rng & ",,RIGHT(B$1,FIND(""_"",B$1)-1))"
   
End Sub
Yes thank you Joe4. That does seem to work. I have marked this thread as Solved.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top