Range dependent on InputBox

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
721
Office Version
  1. 2016
Platform
  1. Windows
Is it possible to set a cell range based on an inputbox?

As an example I have an inputbox, and based on the users response I would like to set a particular range that can be used throughout my code.

In my mind it would be something like
Select Case strArea
Case 80
x="E12"
Case 82
x="E13"
Case 84
x="E17"

From there I can use Range(x) and based on the above Range("E12") would be used if 80 was entered.

Am I out of my mind?

Thank you
 
As for the other you cant use Range(x) then use Left(x,3). That doesnt make sense. You are overwriting the cell so how can you have the leftmost 3 characters also. Unless you can explain what you want.
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
As for the other you cant use Range(x) then use Left(x,3). That doesnt make sense. You are overwriting the cell so how can you have the leftmost 3 characters also. Unless you can explain what you want.
In this example, if 82 is inputted then in cell E13 the formula would be ="Area " & LEFT(C13,3)
VBA Code:
    Dim strArea As String, y As String
    Select Case strArea
        Case 82
            y = "E13"
        Case 83, 84
            y = "E17"
    End Select
    Select Case strArea
        Case 82, 83, 84
            Rows("4").Delete
            With Worksheets("Dealer Status").Range(y)
            .Formula = "=""Area "" & LEFT(C13,3)"
            .HorizontalAlignment = xlLeft
            End With
End Select

What I am trying to accomplish is making the C13 as part of the above formula be dynamic.

What I was thinking was this, but having to do it without the quotes because there are quotes in the formula =LEFT(C13,3)
VBA Code:
    Dim strArea As String, y As String, z As String
    Select Case strArea
        Case 82
            y = "E13"
            z = E13
        Case 83, 84
            y = "E17"
    End Select
    Select Case strArea
        Case 82, 83, 84
            Rows("4").Delete
            With Worksheets("Dealer Status").Range(y)
            .Formula = "=""Area "" & LEFT(z,3)"
            .HorizontalAlignment = xlLeft
            End With
End Select
But that didn't work
 
Upvote 0
In this example, if 82 is inputted then in cell E13 the formula would be ="Area " & LEFT(C13,3)
VBA Code:
    Dim strArea As String, y As String
    Select Case strArea
        Case 82
            y = "E13"
        Case 83, 84
            y = "E17"
    End Select
    Select Case strArea
        Case 82, 83, 84
            Rows("4").Delete
            With Worksheets("Dealer Status").Range(y)
            .Formula = "=""Area "" & LEFT(C13,3)"
            .HorizontalAlignment = xlLeft
            End With
End Select

What I am trying to accomplish is making the C13 as part of the above formula be dynamic.

What I was thinking was this, but having to do it without the quotes because there are quotes in the formula =LEFT(C13,3)
VBA Code:
    Dim strArea As String, y As String, z As String
    Select Case strArea
        Case 82
            y = "E13"
            z = E13
        Case 83, 84
            y = "E17"
    End Select
    Select Case strArea
        Case 82, 83, 84
            Rows("4").Delete
            With Worksheets("Dealer Status").Range(y)
            .Formula = "=""Area "" & LEFT(z,3)"
            .HorizontalAlignment = xlLeft
            End With
End Select
But that didn't work
I figured it out
VBA Code:
    Dim strArea As String
    Select Case strArea
        Case 82
            y = "E13"
            z = "E12"
        Case 83, 84
            y = "E17"
    End Select
    Select Case strArea
        Case 82, 83, 84
            Rows("4").Delete
            With Worksheets("Dealer Status").Range(y)
            .Formula = "=""Area "" & LEFT(" & z & ",3)"
            .HorizontalAlignment = xlLeft
            End With
End Select
 
Upvote 0

Forum statistics

Threads
1,214,573
Messages
6,120,318
Members
448,956
Latest member
Adamsxl

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