data mathod error !!!!!! help!!!!

killnight

New Member
Joined
Sep 7, 2011
Messages
4
Private Sub CommandButton4_Click()
ShowPic
End Sub

Sub ShowPic()
For i = 1 To 310
myvar = Application.WorksheetFunction _
.VLookup(Worksheets("sheet1").Range("b" & i + 1), Worksheets("sheet1").Range("B:O"), 14, False)
OLEObjects("image" & i).Picture = LoadPicture(myvar)
Me.Controls("image" & i).Picture = LoadPicture(myvar)
i = i + 1
End Sub

Something thing is wrong when I replace ShowPic1 with Me.Controls("image" & i)

:(:confused:
help me!!


 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Welcome to MrExcel.

Are your image controls on a UserForm or on a Worksheet? Me.Controls would apply only to a UserForm. For a worksheet try:

Code:
Me.OLEObjects("image" & i).Object.Picture = LoadPicture(myvar)
 
Upvote 0
Welcome to MrExcel.

Are your image controls on a UserForm or on a Worksheet? Me.Controls would apply only to a UserForm. For a worksheet try:

Code:
Me.OLEObjects("image" & i).Object.Picture = LoadPicture(myvar)

Thank you very much,
your code can work very well.
It's just what I want.

Every time while I want do loop and put a "i" in the code to make work easyer.Things turned up to be a hell.I know it's becase I didn't learn the basic knowledge well. But the hell is I don't know what I don't know.Do you mind tell me in order to know these thing what I should read. It seamed not write in common textbook.thanks again.

a code like this
Private Sub CommandButton1_Click()
ShowPic1
ShowPic2
ShowPic3
ShowPic4
ShowPic5
ShowPic6
ShowPic7
ShowPic8
ShowPic9
ShowPic10
End Sub

while I put a "i" everything stop work.

Private Sub CommandButton1_Click()
For i = 1 To 10
"showpic"& i
Next i
End Sub

It do not work in this line too.

Private Sub CommandButton1_Click()
For i = 1 To 10
call sub("showpic"& i)
Next i
End Sub
 
Upvote 0
This time the code do not work.

Error No. 1004
"the Macro can't use in this worksheet or alll the macro is forbidden to use in this worksheet.


Private Sub CommandButton2_Click()
i = 1
Application.Run "msgbox" & i
End Sub

Sub msgbox1()
MsgBox "msgbox1"
End Sub
 
Upvote 0
yes this time it worked.
thanks a lot.

I find out the reason inorder to learn more I rewrite the code.




Private Sub CommandButton2_Click()
i = 1
Application.Run "sheet1.msgbox" & i
End Sub
Sub msgbox1()
MsgBox "msgbox1"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,596
Messages
6,179,807
Members
452,944
Latest member
2558216095

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