PDA

View Full Version : Solved: User Defined Function Question



mbake16
04-13-2009, 06:13 AM
Attached is an example of how I'm using a UDF to paste values in a column on one sheet into a column on another sheet.

If there is no value in a cell on the first sheet, nothing is to be pasted into the column on the second sheet, however a "0" is always pasted for cells in the first sheet having no value.

If anyone can let me know how to adjust my code to have nothing pasted for cells with no value instead of a "0" that would be great!


Thanks,


Matt

lucas
04-13-2009, 06:22 AM
You could call your funtion with an if statement. I have changed the hightlighted formula's in the attachment:

=IF(data!A49<>"",UPCLookUp(data!A49),"")

lucas
04-13-2009, 06:28 AM
You can also use a vba method. Add the following to the thisworkbook module:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
ActiveWindow.DisplayZeros = False
End Sub
http://www.vbaexpress.com/kb/getarticle.php?kb_id=440

hardlife
04-13-2009, 06:33 AM
Function UPCLookUp(UPC As Range)
If UPC.Value <> "" Then
UPCLookUp = UPC.Value
Else
UPCLookUp = ""
End If
End Function

lucas
04-13-2009, 06:40 AM
Hardlife's solution works very well. Hardlife, if you select your code when posting and hit the vba button it will be formatted for the forum as I have done to your code in post #4

mbake16
04-13-2009, 08:50 AM
Thank you Lucas and hardlife, both of your suggestions work great! Thanks for taking the time to point me in the right direction.


Matt