VBA Integer Overflow at 70,000

The website you are looking at is for Visual Studio (.NET) . VBA Integer is 32,768. You need to use a long. A VBA Long variable holds whole numbers from -2,147,483,648 to 2,147,483,647 and uses 4 bytes (32 bits) of memory. Dim lLastRow as Long

Excel VBA: Can’t get a match, error “Unable to get the Match property of the WorksheetFunction class”

Use the Application.Match function which allows for better ability to trap errors. When using the WorksheetFunction.Match, when a match is not found, it returns an error, which is what you’re experiencing. If Not IsError(Application.Match(Cells(e, 1).Value, myrange, 0)) Then ‘Do stuff when the match is found Cells(e, 3).Value = “Yes” Else: Cells(e, 3).Value = “No” End … Read more

Excel vba add code to sheet module programmatically

Use this to add a workbook and place a worksheet change event into the Sheet1 module. Sub AddSht_AddCode() Dim wb As Workbook Dim xPro As VBIDE.VBProject Dim xCom As VBIDE.VBComponent Dim xMod As VBIDE.CodeModule Dim xLine As Long Set wb = Workbooks.Add With wb Set xPro = .VBProject Set xCom = xPro.VBComponents(“Sheet1”) Set xMod = … Read more

VBA collection: list of keys

If you intend to use the default VB6 Collection, then the easiest you can do is: col1.add array(“first key”, “first string”), “first key” col1.add array(“second key”, “second string”), “second key” col1.add array(“third key”, “third string”), “third key” Then you can list all values: Dim i As Variant For Each i In col1 Debug.Print i(1) Next … Read more