Range Variable (From Cell Value)

RudRud

Active Member
Joined
Feb 2, 2023
Messages
275
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. MacOS
Hi Gurus,

If vbNo , inpboxa & b will become as a range variable, therefore when i put inpboxa.select it will be selected

However if vbYes, inpboxa cant be select. Any quick thoughts for selecting an inpboxa when vbyes? Thanks

VBA Code:
Sub test()

answer = MsgBox("Last Range (Yes), New Range(No) ", vbYesNo)
If answer = vbYes Then
inpboxa = Range("b2").Value
inpboxb = Range("b3").Value

ElseIf answer = vbNo Then
    Set inpboxa = Application.InputBox(Prompt:="Select a range", Type:=8)
   Set inpboxb = Application.InputBox(Prompt:="Select a range", Type:=8)
   Range("b2").Value = inpboxa.Address
   Range("b3").Value = inpboxb.Address
End If

inpboxa.Select
End Sub
 
I will take note for that and i'll try to be more clearer in the future. Thanks for the fast response anyway :)
You are welcome.

I would recommend using "Option Explicit" in all your code, which requires you to declare all variables before using them.
This will help in debugging and cut down on errors/typos.
See this article to see how to automatically turn it on for all new projects: How to use Option Explicit Statement in VBA
 
Upvote 0

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
You are welcome.

I would recommend using "Option Explicit" in all your code, which requires you to declare all variables before using them.
This will help in debugging and cut down on errors/typos.
See this article to see how to automatically turn it on for all new projects: How to use Option Explicit Statement in VBA

Noted, Thanks for your kind sharing. It means a lot for us to grow everyday :)
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

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