Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA Macro - with UserForm and If Then Stmt 1

Status
Not open for further replies.

restrada2

Technical User
Jun 3, 2008
1
US
Dear People,
Please Help. I have to write macro for work that would let user choose date ( thus the ListBox1),
then depending on date chosen the cells would be cleared. When I run this macro,
regardless of the date that i choose it deletes data from Jan 08 - Mar 08 at the same time.
I have try everything.

How do I modify macro so if user chooses Mar 08 only that data would be delete and



Private Sub CancelButton_Click()
Unload UserForm1
End Sub

Private Sub ListBox1_Click()

End Sub

Private Sub OKButton_Click()
If Range("AO10") = "Jan 2008" Then Range( _
"E11:E26,E30:E32,E36:E37,E41:E43,E50:E53 _
E55:E56,E59,E64:E66,E68:E71,E76,E82:E84,E86:E88,E94").Select
Selection.ClearContents
If Range("AO11") = "Feb 2008" Then Range( _
"G11:G26,G30:G32,G36:G37,G41:G43,G50:G53,G55:G56,G59,G64:G66 _
,G68:G71,G76,G82:G84,G86:G88,G94").Select
Selection.ClearContents
If Range("AO12") = "Mar 2008" Then Range( _
"I11:I26,I30:I32,I36:I37,I41:I43,I50:I53,I55:I56,I59,I64:I66,I68:I71,I76,I82:I84,I86:I88,I94").Select
Selection.ClearContents

Unload UserForm1
 
What do you have in AO10, AO11 & AO12? I'm guessing AO10 = "Jan 2008", AO11 = "Feb 2008" & AO12 = "Mar 2008"

Are you putting the value from ListBox1 into a cell? If this is AO10 then you're code should be along the lines of:

If Range("AO10") = "Jan 2008" then...
If Range("AO10") = "Feb 2008" then...
If Range("AO10") = "Mar 2008" then...

Whereas your code has if AO10 = Jan... AO11 = Feb... AO12 = Mar...

 




Yes, Your selection value ought to be placed into ONE CELL, not diffeent cells!!!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top