Manu Mohan
Manu Mohan

Reputation: 177

Verify a variable contains Valid Range address in excel VBA

I have tried to get a value Range address value in to a variable.

searchWrd = InputBox("Please enter the column name of first word/token's", "Search String", "J1")

I need to verify the variable searchWrd contains a valid address or not. Also what should be the data type for the variable searchWrd

Upvotes: 0

Views: 726

Answers (2)

Ralph
Ralph

Reputation: 9444

I'd go with

searchWrd = Application.InputBox("lease enter the column name of first word/token's", "Search String", ,,,,,8)

For more information read this: https://msdn.microsoft.com/en-us/library/office/ff839468.aspx

Basically, the 8 at the end sets the input type to be a range. Note, that this will also allow you to immediately Dim searchWrd as Range.

Upvotes: 1

Pearli
Pearli

Reputation: 159

You could try to verify the Text you get from the Inputbox by using a normal If-Then-construct. To get the correct data type we Need to know what should be possbible to type into the Inputbox. Normally i would try to get the Row/Column Number of the Row/Column the Search string is located at. Or, much better, to ask for the string it self and write the code to look up where it is located. So i only Need to check for spelling Errors and give a message that the string isn't found. It's better then asking for a range i think.

Upvotes: 0

Related Questions