#1
|
||||
|
||||
Dim statement for Split array
I don't understand why this code works: Code:
Dim BlueLite As String 'Light blue RBG values BlueLite = "219,229,241" '. Dim RGBVals As Variant 'Array for indivicdual RGB values RGBVals = Split(BlueLite, ",") '. Code:
Dim BlueLite As String 'Light blue RBG values BlueLite = "219,229,241" '. Dim RGBVals() As Variant 'Array for indivicdual RGB values RGBVals = Split(BlueLite, ",") '. |
#2
|
||||
|
||||
If you declare an array, you need to populate it with code like:
Code:
Dim x As Long, y as long Dim BlueLite As String 'Light blue RBG values BlueLite = "219,229,241" '. Dim RGBVals() As Variant 'Array for indivicdual RGB values x = UBound(Split(BlueLite, ",")) ReDim RGBVals(x) For i = 0 To x RGBVals(y) = Split(BlueLite, ",")(y) '. Next
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
Quote:
Code:
Dim varname() . . . Code:
Dim sLiteBlue As String sLiteBlue = "219,229,241" Dim RGBVals RGBVals = Split(sLiteBlue, ",") Code:
?rgbvals(0) 219 ?rgbvals(1) 229 ?rgbvals(2) 241 Code:
?RGB(RGBVals(0), RGBVals(1), RGBVals(2)) 15853019 Quote:
Code:
Dim sLiteBlue As String sLiteBlue = "219,229,241" Dim iLiteBlue As Long Dim RGBVals As Variant RGBVals = Split(sLiteBlue, ",") iLiteBlue = RGB(RGBVals(0), RGBVals(1), RGBVals(2)) |
#4
|
||||
|
||||
So why not simply pass the RGB value as a long? That's what the code in https://www.msofficeforums.com/148862-post9.html does via:
Const w As Long = RGB(255, 255, 255) and: s = RGB(198, 217, 241) for example. Regardless, even if you want to pass the rgb values as a string, you don't need the array. You could, for example, use: Code:
Dim r As Long, g As Long, b As Long, iLiteBlue As Long Const sLiteBlue As String = "219,229,241" r = Split(sLiteBlue, ",")(0) g = Split(sLiteBlue, ",")(1) b = Split(sLiteBlue, ",")(2) iLiteBlue = RGB(r, g, b)
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
||||
|
||||
Quote:
I was able to get something almost as good to work. Code:
Dim Blue As Long: Blue = RGB(219, 229, 241) Dim White As Long: White = RGB(255, 255, 255) |
#6
|
||||
|
||||
Quote:
Dim w As Long: w = RGB(255, 255, 255) rather like you're using. To use 'Const w As Long =', one would have to use the actual RGB value, not the RGB function
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Mail Merge - split merged documents and rename each split document based on text in header | FuriousD | Word VBA | 1 | 05-12-2019 04:06 AM |
Converting a Select statement in Excel to an update statement | shabbaranks | Excel Programming | 5 | 10-31-2018 11:47 PM |
Split word file into several PDF using the bookmarks as split positions and name | Fixxxer | Word VBA | 7 | 10-08-2018 01:10 AM |
Split function in Excel (split the screen) | Officer_Bierschnitt | Excel | 1 | 07-05-2017 07:02 AM |
Convert String Array to Integer Array from a User Input? | tinfanide | Excel Programming | 4 | 12-26-2012 08:56 PM |