I've come across this a couple of times recently and was just curious if there was an easier way to do this...
With Activeworkbook
'Do Stuff
With .Sheets(1)
'More stuff Done
'...
'But now I need to refer to or pass the Sheet in the last With Statement
SomeFunctionAnswer = SomeFunction Activeworkbook.Sheets(1)
End With
'Yet more stuff Done
End With
Does it have to be fully written out, or is there some way of notating it that makes it easier/cleaner? Perhaps there is some sort of property or method to pass itself for just this instance? What about referring to a property or method from the higher With?
SomeFunctionAnswer = SomeFunction .Self '???
'OR
SomeFunctionAnswer = SomeFunction .Parent.Name '???
Hope that makes sense...
A nested IF is just two more IF statements in a formula, where one IF statement appears inside the other. To illustrate, below I've extended the original pass/fail formula above to handle "incomplete" results by adding an IF function, and nesting one IF inside the other: = IF(C3 = "","Incomplete",IF(C3 >= 65,"Pass","Fail"))
The top-nested operator accepts tabular data as input, and one or more aggregation clauses. The first aggregation clause (left-most) subdivides the input records into partitions, according to the unique values of some expression over those records.
Because a nested IF formula returns a value corresponding to the first TRUE condition. Therefore, in your nested IF statements, it's very important to arrange the conditions in the right direction - high to low or low to high, depending on your formula's logic.
What nesting means Nesting simply means to combine formulas, one inside the other, so that one formula handles the result of another. For example, here's a formula where the TODAY function is nested inside the MONTH function:
... curious if there was an easier way to do this... Does it have to be fully written out,...?
I too have had this problem; an example is transferring data from a TYPE
structure to a database RST
structure, where I would like to use the dot-notation in the innermost With
/EndWith
statement block.
I came up with the following:
Function AddTypdataToDB(dbs As Database, typData As typAddressInfo)
Dim rst As Recordset
Set rst = dBase.rstOpenRecordset(dbs, "SELECT * FROM Master")
rst.AddNew
With typData
rst.Fields("Amenities") = .strAmenities
rst.Fields("BusinessName") = .strBusinessName
rst.Fields("CountOfBathrooms") = .strCountOfBathrooms
rst.Fields("CountOfBeds") =
rst.Fields("CountOfGuests") =
Here, I am partway through writing the VBA program code with my least-effort mechanism to date:
.strAmnenities
part and then ...TYPE
structure.This sounds complex when I write it out in English, but it is the fastest error-free way I have found to generate code manually.
I have eliminated the outer WITH
statement and used explicit RST
code, but the bulk of that is copy/pasted.
Not only do I reduce the elapsed time to generate a block of VBA code for my AddRecord
procedure, but I save time by not having to correct the myriad errors that creep in when I code in “long-hand”.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With