excel-vba

Sorting a collection of objects in VBA

吃可爱长大的小学妹 提交于 2020-06-25 04:38:23
问题 I'm trying to write a function that would sort a collection of objects. Since the objects are all of the same type (the same user-defined class), their property set is the same. Is it possible to discover the object's properties (through code) so as to put the collection in a bi-dimensional array, each row being for an object, each column for one of its property? Another solution would be to copy each object from the collection to an array of objects, and sort them by one of their property,

Sorting a collection of objects in VBA

心已入冬 提交于 2020-06-25 04:38:04
问题 I'm trying to write a function that would sort a collection of objects. Since the objects are all of the same type (the same user-defined class), their property set is the same. Is it possible to discover the object's properties (through code) so as to put the collection in a bi-dimensional array, each row being for an object, each column for one of its property? Another solution would be to copy each object from the collection to an array of objects, and sort them by one of their property,

Using VBA to control another program entirely

徘徊边缘 提交于 2020-06-25 04:06:32
问题 I'm currently working on simplifying a process at work. It involves a Chatillon DFIS Force Meter which uses a serial connection to transmit data. The data gets sent to the Chattillon program as text and can only be saved as a .dat file. I'm trying to set up an Excel workbook that can just automatically open the program and have different commands to put the information straight into Excel. The Commands would involve changing the units, zeroing the sensor, and transmitting. I've done some

excel VBA break execution when there's no break key on keyboard

依然范特西╮ 提交于 2020-06-24 20:32:40
问题 I'm just noticing that on my laptop (Dell XPS 15z) there's no BREAK key (no dedicated number keypad). I'm running the debugger step-by-step and then when all seems fine, I just let it play out. However, it's running in an infinite loop and now I'm realizing there's no way to stop it without the break key!!!! Is this a bad joke? I had to reboot the computer; is there a more graceful way?? Thanks. 回答1: just press the escape key twice ;-) 回答2: Solution #1 (It works most of the time): When some

excel VBA break execution when there's no break key on keyboard

随声附和 提交于 2020-06-24 20:32:08
问题 I'm just noticing that on my laptop (Dell XPS 15z) there's no BREAK key (no dedicated number keypad). I'm running the debugger step-by-step and then when all seems fine, I just let it play out. However, it's running in an infinite loop and now I'm realizing there's no way to stop it without the break key!!!! Is this a bad joke? I had to reboot the computer; is there a more graceful way?? Thanks. 回答1: just press the escape key twice ;-) 回答2: Solution #1 (It works most of the time): When some

Excel VBA debugger stops without error or warning

感情迁移 提交于 2020-06-23 14:16:06
问题 While trying to test some code, I am having an issue that I don't recall running into before. When I step through the code it halts after the ClearContents line...there is no error, no warning, nothing. Public Sub CreateCurMth(wsCur As Worksheet) Dim iData As Integer, iRow As Integer Dim wbData As Workbook On Error GoTo err_here iRow = wsCur.Cells(Rows.Count, 1).End(xlUp).Row wsCur.Range("A10:X" & iRow).ClearContents '<----- Fails after this line 'Assume that file is already open Set wbData =

Excel VBA - Use VlookUp Inside Is Error

有些话、适合烂在心里 提交于 2020-06-23 14:14:15
问题 I need to do a vlookup through a range of cells, and depending on it returning a value or a #N/A, I want to do some action on it. I tried to place the vlookup inside the iserror function but that didn't work. This is what i tried next but is also not working: Set costCentreMapping = Workbooks.Open(Filename:="C:\mapping.xlsx") Sheets("Sheet2").Activate Dim CostCentreRange As Range Set CostCentreRange = Range("A4:E2967") Set test1 = Application.WorksheetFunction.VLookup(appid, CostCentreRange,

Excel VBA - Use VlookUp Inside Is Error

有些话、适合烂在心里 提交于 2020-06-23 14:14:09
问题 I need to do a vlookup through a range of cells, and depending on it returning a value or a #N/A, I want to do some action on it. I tried to place the vlookup inside the iserror function but that didn't work. This is what i tried next but is also not working: Set costCentreMapping = Workbooks.Open(Filename:="C:\mapping.xlsx") Sheets("Sheet2").Activate Dim CostCentreRange As Range Set CostCentreRange = Range("A4:E2967") Set test1 = Application.WorksheetFunction.VLookup(appid, CostCentreRange,

Why can't I use the “Any” as a name in VBA?

老子叫甜甜 提交于 2020-06-22 20:36:25
问题 While trying to define an Any() function like python's, I found that I couldn't name anything "Any". Attempting to name a Function, Sub, Const, or variable any will throw a syntax error and the VBA IDE will highlight it. I know any not a particularly great name, but why is it throwing a syntax error? The only reason I could think of was that it might be a reserved keyword, but it's not. 回答1: VBA (Visual Basic for Applications) is not VB.NET, even though they share the same "Visual Basic"

Why can't I use the “Any” as a name in VBA?

喜你入骨 提交于 2020-06-22 20:35:07
问题 While trying to define an Any() function like python's, I found that I couldn't name anything "Any". Attempting to name a Function, Sub, Const, or variable any will throw a syntax error and the VBA IDE will highlight it. I know any not a particularly great name, but why is it throwing a syntax error? The only reason I could think of was that it might be a reserved keyword, but it's not. 回答1: VBA (Visual Basic for Applications) is not VB.NET, even though they share the same "Visual Basic"