ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Macro error - cant work it out... (https://www.excelbanter.com/excel-worksheet-functions/221939-macro-error-cant-work-out.html)

NPell

Macro error - cant work it out...
 
Dim icon As Variant
Dim myicon As Variant
myicon = Array("icona1", "icona2", "icona3", "icona4", "icona5",
"icona6", "icona7", "icona8", "icona9", "icona10", "icona11",
"icona12")
myref = Array("d3", "d4", "D5", "D6", "D7", "D8", "D9", "D10", "D11",
"D12", "D13", "D14")
I = LBound(myref)

For Each icon In myicon
Set myicon.Picture = LoadPicture("filepath" & Sheets("Sheet1").Range
(myref(I)).Value & ".bmp")
I = I + 1
Next icon

---------------------------------

This works as
Set icona1.Picture = LoadPicture("filepath" & Sheets("Sheet1").Range
("D3").Value & ".bmp")
Set icona2.Picture = LoadPicture("filepath" & Sheets("Sheet1").Range
("D4").Value & ".bmp")
etc..

So why not with the For statement...

Any suggestions?

Cheers

OssieMac

Macro error - cant work it out...
 
Untested but the following does not look correct.
Set myicon.Picture = LoadPicture etc

myicon is your entire array. In the for each (icon is the individual element)

Shouldn't it be
Set icon.Picture = LoadPicture etc


--
Regards,

OssieMac


"NPell" wrote:

Dim icon As Variant
Dim myicon As Variant
myicon = Array("icona1", "icona2", "icona3", "icona4", "icona5",
"icona6", "icona7", "icona8", "icona9", "icona10", "icona11",
"icona12")
myref = Array("d3", "d4", "D5", "D6", "D7", "D8", "D9", "D10", "D11",
"D12", "D13", "D14")
I = LBound(myref)

For Each icon In myicon
Set myicon.Picture = LoadPicture("filepath" & Sheets("Sheet1").Range
(myref(I)).Value & ".bmp")
I = I + 1
Next icon

---------------------------------

This works as
Set icona1.Picture = LoadPicture("filepath" & Sheets("Sheet1").Range
("D3").Value & ".bmp")
Set icona2.Picture = LoadPicture("filepath" & Sheets("Sheet1").Range
("D4").Value & ".bmp")
etc..

So why not with the For statement...

Any suggestions?

Cheers


NPell

Macro error - cant work it out...
 
On Feb 23, 11:52*am, OssieMac
wrote:
Untested but the following does not look correct.
Set myicon.Picture = LoadPicture etc

myicon is your entire array. In the for each (icon is the individual element)

Shouldn't it be
Set icon.Picture = LoadPicture etc

--
Regards,

OssieMac



"NPell" wrote:
Dim icon As Variant
Dim myicon As Variant
myicon = Array("icona1", "icona2", "icona3", "icona4", "icona5",
"icona6", "icona7", "icona8", "icona9", "icona10", "icona11",
"icona12")
myref = Array("d3", "d4", "D5", "D6", "D7", "D8", "D9", "D10", "D11",
"D12", "D13", "D14")
I = LBound(myref)


For Each icon In myicon
Set myicon.Picture = LoadPicture("filepath" & Sheets("Sheet1").Range
(myref(I)).Value & ".bmp")
I = I + 1
Next icon


---------------------------------


This works as
Set icona1.Picture = LoadPicture("filepath" & Sheets("Sheet1").Range
("D3").Value & ".bmp")
Set icona2.Picture = LoadPicture("filepath" & Sheets("Sheet1").Range
("D4").Value & ".bmp")
etc..


So why not with the For statement...


Any suggestions?


Cheers- Hide quoted text -


- Show quoted text -


I dont think so, because it is saying that whatever the value of
myicon is at this time...
Then it will be the 2nd value on the 2nd loop... etc.
I will try it though.
Thanks for responding.

Bob Phillips[_3_]

Macro error - cant work it out...
 
But icon points to the element in the myIcon array. So you extract the value
in icon, but you cannot then use that as an object to associate the picture
to. Maybe you need an array of picture objects.

--
__________________________________
HTH

Bob

"NPell" wrote in message
...
On Feb 23, 11:52 am, OssieMac
wrote:
Untested but the following does not look correct.
Set myicon.Picture = LoadPicture etc

myicon is your entire array. In the for each (icon is the individual
element)

Shouldn't it be
Set icon.Picture = LoadPicture etc

--
Regards,

OssieMac



"NPell" wrote:
Dim icon As Variant
Dim myicon As Variant
myicon = Array("icona1", "icona2", "icona3", "icona4", "icona5",
"icona6", "icona7", "icona8", "icona9", "icona10", "icona11",
"icona12")
myref = Array("d3", "d4", "D5", "D6", "D7", "D8", "D9", "D10", "D11",
"D12", "D13", "D14")
I = LBound(myref)


For Each icon In myicon
Set myicon.Picture = LoadPicture("filepath" & Sheets("Sheet1").Range
(myref(I)).Value & ".bmp")
I = I + 1
Next icon


---------------------------------


This works as
Set icona1.Picture = LoadPicture("filepath" & Sheets("Sheet1").Range
("D3").Value & ".bmp")
Set icona2.Picture = LoadPicture("filepath" & Sheets("Sheet1").Range
("D4").Value & ".bmp")
etc..


So why not with the For statement...


Any suggestions?


Cheers- Hide quoted text -


- Show quoted text -


I dont think so, because it is saying that whatever the value of
myicon is at this time...
Then it will be the 2nd value on the 2nd loop... etc.
I will try it though.
Thanks for responding.




All times are GMT +1. The time now is 02:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com