0

When I run this code, I get an error saying that I have a run time error 6

Dim ProjectNumber As Integer
Dim XProjectFolder As String


ProjectNumber = projectinfosheet.Range("B10")

If Target.Address = "$B$10" Then

    XProjectFolder = Application.WorksheetFunction.VLookup(ProjectNumber & "*", FolderRng, 1, False)
    projectinfosheet.Range("E1").Value = XProjectFolder
    MsgBox XProjectFolder
End if

But when I comment Dim ProjectNumber As Integer out, the code run smoothly. Am I dimensioning my variables incorrectly?

RawrRawr7
  • 333
  • 2
  • 12
  • 1
    What if you change it from an Integer to a Long? – braX Dec 24 '21 at 00:54
  • hey that works! – RawrRawr7 Dec 24 '21 at 00:55
  • Integers have a limit of 32,767, so you must have exceeded that. – braX Dec 24 '21 at 00:56
  • hmm...I'm still getting errors when I change to different project numbers. The error this time is Unable to get the Vlookup property of the WorksheetFunction class – RawrRawr7 Dec 24 '21 at 00:58
  • Note: You have almost no reason to use `Integer` in VBA nowadays so just declare them as `Long` moving forward. – Raymond Wu Dec 24 '21 at 00:58
  • Like what number for example? – braX Dec 24 '21 at 00:59
  • 141864 ...... <---ignore those dots. I had to use them to post a comment – RawrRawr7 Dec 24 '21 at 01:00
  • The code runs smoothly when I type in 139280. But numbers higher than that seems to give me issues. – RawrRawr7 Dec 24 '21 at 01:01
  • Could you post the complete code? The declaration and reference to `FolderRng` are missing. There are a few events that have `Target` as an argument. A `VLookup` with the third argument set to `1` makes little sense. Please describe when and what the code is supposed to do. – VBasic2008 Dec 24 '21 at 01:23
  • For the error regarding `VLookup`, see [this](https://stackoverflow.com/questions/18063214/how-to-error-handle-1004-error-with-worksheetfunction-vlookup) – BigBen Dec 24 '21 at 01:53

0 Answers0