Microsoft Excel 2010 macro help

donchua1

Junior Member
Joined
Jun 7, 2015
Messages
1
Reaction score
0
Hi all,



i do not know how to remove the pictures when i unclick the CheckBox. The picture just duplicate when i unclick the checkbox.

my codes are as follows


Private Sub Main_Initialize()

GetData
CheckBox22.Value = False
End Sub

Sub CheckBox22_Change()

If CheckBox22.Value = True Then
Sheets("Database").Shapes("001").Copy
Sheets("Main").Paste Destination:=Range("F6")
Sheets("Database").Shapes("101").Copy
Sheets("Main").Paste Destination:=Range("F13")
Sheets("Database").Shapes("201").Copy
Sheets("Main").Paste Destination:=Range("F19")
Application.CutCopyMode = False

Else

Sheets("Main").Shapes("001").Delete
Sheets("Main").Shapes("101").Delete
Sheets("Main").Shapes("201").Delete
End If



End Sub

Sub CheckBox23_Change()

If CheckBox23.Value = True Then
Sheets("Database").Shapes("001").Copy
Sheets("Main").Paste Destination:=Range("G6")
Sheets("Database").Shapes("101").Copy
Sheets("Main").Paste Destination:=Range("G13")
Sheets("Database").Shapes("201").Copy
Sheets("Main").Paste Destination:=Range("G19")
Application.CutCopyMode = False

Else

Sheets("Main").Shapes("002").Delete
Sheets("Main").Shapes("102").Delete
Sheets("Main").Shapes("202").Delete
End If



End Sub

My tabs names are Main and Database. Will appreciate any help from any gurus in this forum.

Thanks!
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,547
Reaction score
1,301
Hi all,



i do not know how to remove the pictures when i unclick the CheckBox. The picture just duplicate when i unclick the checkbox.

my codes are as follows


...

My tabs names are Main and Database. Will appreciate any help from any gurus in this forum.

Thanks!

Run your codes through the debugger, and step through it, find out how the execution flow through your codes.
 

peterchan75

Supremacy Member
Joined
Apr 26, 2003
Messages
6,722
Reaction score
529
For debugging purpose, you may want to dump all the shape names into another worksheet. You need to create another worksheet name "Sheet3" for this example to work.

Dim sh as shape
Dim i as integer

i=0

For Each sh in Sheets("Main").Shapes
Sheets("Sheet3").Range("A1").Offset(i,0)=sh.Name
i=i+1
Next

Once the names are verify, this statement should work.

Sheets("Main").Shapes("whatever names").Delete

Another thing to verify is whether the IF-ELSE statement catch the check and uncheck logic.
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top