Construct a line of code using values of an array

SeniorNewbie

New Member
Joined
Jul 9, 2023
Messages
35
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
  2. MacOS
Hi out there,

my target is to construct a code line by loop through an array with the values of iR,iG. iB. All my attempts end in Type mismatch, No such Property or similar errors.
The following code show my attempts:
VBA Code:
Sub Colors()
Dim aColors, i As Integer, sParam As String

'aColors = Array("255, 0, 0", "255, 100, 100")                  'for line 55
'aColors = Array("RGB(255, 0, 0)", "RGB(255, 100, 100)")        'for line 56
'aColors = Array(" = RGB(255, 0, 0)", " = RGB(255, 100, 100)")  'for line 57

For i = 0 To UBound(aColors)
    With ActiveSheet
        sParam = aColors(i)
        '.Cells(i + 1, 1).Interior.Color = RGB(aColors(i))
        '.Cells(i + 1, 1).Interior.Color = sParam
        '.Cells(i + 1, 1).Interior.Color sParam
    End With
Next i

End Sub
To test the code the corresponding two lines have to be activated.

Any idea what's my mistake?

THX in advance
Senior Newbie
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
How about
VBA Code:
Sub Colors()
Dim aColors, i As Integer, sParam As String

aColors = Array(Array(255, 0, 0), Array(255, 100, 100))                 'for line 55
'aColors = Array("RGB(255, 0, 0)", "RGB(255, 100, 100)")        'for line 56
'aColors = Array(" = RGB(255, 0, 0)", " = RGB(255, 100, 100)")  'for line 57

For i = 0 To UBound(aColors)
    With ActiveSheet
'        sParam = aColors(i)
        .Cells(i + 1, 1).Interior.Color = RGB(aColors(i)(0), aColors(i)(1), aColors(i)(2))
        '.Cells(i + 1, 1).Interior.Color = sParam
        '.Cells(i + 1, 1).Interior.Color sParam
    End With
Next i

End Sub
 
Upvote 0
Solution
Hi Fluff,

thank you so much! it works. I didn't think, that's necessary to seperate the values. I hoped it's easier ... but anyway THX a lot!!

Have a nice day
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,216,499
Messages
6,131,012
Members
449,613
Latest member
MedDash99

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top