Please advise on this code & maybe another alternative

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,983
Office Version
  1. 2007
Platform
  1. Windows
On my sheet i have a database where when i make a selection from a drop down the cells are filled with values from a range & also an IF vlookup is used.
All works well until i wish to add to the database & code needs to be updated.

Code in use in cell C3
VBA Code:
=IFERROR(IF(VLOOKUP($B18,$F:$H,3,FALSE)=0,"", VLOOKUP($B18,$F:$H,3,FALSE)),"")

Now when i try to alter the code & paste it in my first cell i notice that when i leave the cell its removed thus cell being empty.

I code in use is shown below & ive tracked the issue down to the line in Red.
Who can it be written another way without my issue.
Thanks


Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.CountLarge > 1 Then Exit Sub

If Intersect(Target, Range("A2:D29")) Is Nothing Then Exit Sub

Application.EnableEvents = False

Target = UCase(Target)

Application.EnableEvents = True

End Sub

Is this code just for changing the text to uppercase OR is it doing something else ?
 
The default property of a range is Value, so
Target =Target is essentially the same as
Target.Value = Target.Value
This will replace the formula with the "value" the formula returns.
If the formula returns "" as will happen if the vlookup return value is 0 or if the IFERROR kicks in then the expression will convert the "" to an empty cell.
The UCase just uppercases any text value that can be upper cased but the formula will be gone.
 
Upvote 0
So what should i do.
I need to update as & when i need too.
I have OCD so Uppercase is a must for me.

Removing Target = UCase (Target) allowed me to update but when its in place the Formula is removed from cell.
 
Upvote 0
OK
Do i also delete that Worksheet_Change code or just the UCase part of it

I see that applies UCase only to the column its in whereas before its applied to my range on the sheet
 
Last edited:
Upvote 0
Adjust the range in the code so it doesn't include cells with the formula in them
 
Upvote 0
Ialso have another formula in the next column of which is
VBA Code:
=IFERROR(VLOOKUP($B3,$F:$H,2,FALSE),"")

Please advise how it would be written to also take onboard the UPEER part

Thanks

Looking to edit range now
 
Upvote 0

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