0

I'm pretty sure this is possible to do but, i have a Variable "DataRowStart" which is assigned a values by the user through an input box, e.g. "A" is there a way to use that variable to define the start of an search? I need this as the location of the data search will change from use to use.

I currently have this line of code for the search;

LastRowNumber = Range("DataRowStart:DataRowStart").Find(What:="", after:=Range(Cells(DataColumn, 1)), searchdirection:=xlPrevious).Row 

And whenever i run the code i get

Method 'Range' of Object'_ Global failed

error.

I defined the variable as a Global DataRowStart as String in the macro that runs this.

I found that this was the best solution as this part of the code is run in a User Form.

Is someone able to point me in the right direction to solve this issue?

Many thanks

Mark

8
  • 1
    is "A" you are getting through an InputBox suppose to be a Column or Row ? Commented Dec 11, 2017 at 15:08
  • I was expecting a full range reference like "A1" Commented Dec 11, 2017 at 15:09
  • DataRowStart is part of a literal string, not a variable. Commented Dec 11, 2017 at 15:10
  • @ShaiRado yes the "A" is meant to det which column is serached for data Commented Dec 11, 2017 at 15:11
  • @QHarr If i swap out DataRowStart for A the program runs with no issue Commented Dec 11, 2017 at 15:12

1 Answer 1

1

You need to take the variable DataRowStart outside the ".

Change:

LastRowNumber = Range("DataRowStart:DataRowStart") 

to

LastRowNumber = Range(DataRowStart & ":" & DataRowStart) 

And also:

Range(Cells(1, DataColumn) 

To:

Range(DataColumn & 1) 
Sign up to request clarification or add additional context in comments.

4 Comments

when i run this code i now get "Application-defined or object error" which is think is from the Range(Cells(DataColumn,1)) section. Would i be right in thinking this? IGNOR THIS MISTYPED A LETTER
Unfortunetly, when i run this code, after this letter mistype i still get the saame Metho'Range... error
@CptGoodar yes, you are correct. see edited code. I changed it according to DataColumn represents a Column.
That solved it and is now working as intend. Thank you very much,

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.