0

I am trying to set a value for CurrentClient Variable i have defined below and then using it to count how many times it Occurs in a range. I am not sure what am i doing wrong here . It is giving me error: "runtime error 9 subscript out of range" on step where it is assigning the value from Sheet 2 cell A2 to Currentclient.

Please help.

Sub GetValue()

Dim ClientCnt As Integer
Dim CurrentClient As String

CurrentClient = Sheets("Sheet 2").Range("A2").Text

ClientCnt = Application.WorksheetFunction.CountIf(Range("A:A"), CurrentClient)

End Sub
3
  • Instead of .Text try .Value Commented Sep 18, 2014 at 18:37
  • Tried .value also it is giving the same error. Commented Sep 18, 2014 at 18:37
  • A2 have a text value which i need to use to set the ClientCnt. I have used variant also instead of String datatype and it is still not working. Commented Sep 18, 2014 at 18:40

1 Answer 1

5

Use Sheet2

rather than

Sheet 2

Sign up to request clarification or add additional context in comments.

6 Comments

Subscript out of range is the critical clue!!
OMG! spent 30 minutes... on this I totttaly missed that. THanks Gary's Student
@Prat14 _________sometimes error messages are useful.
I am new to VBA programming and getting use to it anyways thanks for this lesson i will keep error messages in mind now.
@Prat14 I have made this exact error many times myself. So answering this Post was like greeting an old friend!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.