-
Take the size of the Array
I use this code to fill column headings using an array. However, I use almost the same exact code in multiple places. I would rather the code adjust automatically based on the size of the array is that possible:
Here is some of the code:
[VBA] Range("A1", Cells(1, FinalColumn(wsWorking) + 2)).Value = Array("Whse#", "Whse", "Lot#", "Item#", "Product", "Dept#", "Received", "Shipped", "Adjusted", _
"In Whse", "Reserved", "Allocated", "Held", "Available", "Value")
[/VBA]
see how I take the width of columns then I add values to it if it is not long enough? Well I want it to pick up the size of the array automatically - so I do not need to do this and I can use multiple arrarys in the same code.
-
perhaps:[vba]x = Array("Whse#", "Whse", "Lot#", "Item#", "Product", "Dept#", "Received", "Shipped", "Adjusted", "In Whse", "Reserved", "Allocated", "Held", "Available", "Value")
Range("A1").Resize(, UBound(x) - LBound(x) + 1) = x
[/vba]but note that the bit:
UBound(x) - LBound(x) + 1
is complicated since I don't know whether you've set
Option Base
to 1 or 0
p45cal
Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.
-
I have never set the Option Base so it is the default which I think is 0. Am I correct? So I think I would need the +1 then correct?
-
The extra complexity of the formula is to handle either case, so what the option base is doesn't matter.
If I'd just used UBound, then I'd need to know what the Option Base is.
p45cal
Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules