what is wrong with this macro code?

yichuansancun

Board Regular
Joined
Feb 7, 2011
Messages
123
What I try to achieve is that when the cell named housing_choice = "specified amount", excel should wipe out all the contents in the range with name "housing_m", and if the cell named housing_choice = "m data" then the cell named "housing" should be empty

If Range("housing_choice").Value = "specified amount" Then
Range("housing_m").Select
Selection.Value = ""
ElseIf Range("housing_choice").Value = "m data" Then
Range("housing").Select
Selection.Value = ""
End If


but it won't work... any ideas?

Thanks
 
See if this works

Code:
Sub Macro8()
If LCase(Range("choice").Value) Like "*specified amount*" Then
    Range("housing_selection").ClearContents
ElseIf LCase(Range("choice").Value) Like "*m data*" Then
    Range("housing").ClearContents
End If
SolverOk SetCell:="$N$7", MaxMinVal:=2, ValueOf:="0", ByChange:="$N$3"
SolverSolve userFinish:=True
End Sub
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
OH MY GOD, I think it worked!!!!! I will do more testing... thank you so much!!!! :biggrin:

Just for my learning sake, what makes the differences?

You are awesome!!!
 
Upvote 0
Two things:

I used LCase to make it case-insensitive so Specified Amount would also work.

I used Like with * before and after in case there was other text or spaces in the cell.
 
Upvote 0
Sorry... more issues...

SolverOk SetCell:="$N$7", MaxMinVal:=2, ValueOf:="0", ByChange:="$N$3"
SolverSolve UserFinish:=True

for the above codes, how can I make them work in 2003? Apparently 2003 doesn't have SolverOK?

Thanks,
Perri
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,224
Members
453,152
Latest member
ChrisMd

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