VBA Adding a class to a collection [duplicate]
Remove the parentheses. holdings.Add h Otherwise you are trying to add to the collection the value of the default property of your Holding instance, and it doesn’t have a default property.
Remove the parentheses. holdings.Add h Otherwise you are trying to add to the collection the value of the default property of your Holding instance, and it doesn’t have a default property.
You don’t need VBA for this but still if you want VBA Solution then you can go with any of the other two answers. 🙂 We can use Excel formula to find the Font Color of a cell. See this example. We will be using XL4 macros. Open the Name Manager Give a name. Say … Read more
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
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
Methods It’s always better to loop through an array than a range – it’s much faster. It’s even faster to create a variant data field array with a one liner instead of redimensioning a predeclared array and fill it in an extra loop as proposed by Siddharth Rout (though a good method 🙂 Note: The … Read more
do you want to try the below code I found on the internet somewhere many moons ago and used. It uses the Export function of the Chart object along with the CopyPicture method of the Range object. References: MSDN – Export method as it applies to the Chart object. to save the clipboard as an … Read more
MsgBox is not compatible with non-ANSI unicode characters. We can display message boxes with the WinAPI MessageBoxW function, however, and that is . Let’s declare that function, and then create a wrapper for it that’s nearly identical to the VBA MsgBox function: Private Declare PtrSafe Function MessageBoxW Lib “User32” (ByVal hWnd As LongPtr, ByVal lpText … Read more
vbNullString and “” are different. Here is a webpage exerpt that describes the memory usage differences. “This is the usual way to clear a string variable. Text$ = “” What a waste! First of all, the string “” takes 6 bytes of RAM each time you use it. Consider the alternative: Text$ = vbNullString So … Read more
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
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