1

My code checks the values for cells F8 and H8, and if they're the same it should set CELL A1 to "dim".

Function plchk()

Dim sheet As Worksheet
Set sheet = ActiveWorkbook.Sheets("check")

     If CDbl(Trim(sheet.Range("F8").Value)) = CDbl(Trim(sheet.Range("H8").Value)) Then


       sheet.Range("A1").Value = "dim"


    End If



End Function

On executing this code ,I keep getting the error "VALUE"

Jeff Palson
  • 105
  • 1
  • 1
  • 7
  • 1
    Why `Function` and not `Sub`? Where are you calling this from? – Siddharth Rout Sep 10 '15 at 12:28
  • This part of the code isn't the full scope. It's a function as I will be passing variables into it once I've got the structure ready, and I will be expecting it to return a value as output as well as manipulating specific cells on the sheet. – Jeff Palson Sep 10 '15 at 12:31
  • ok but you are not calling this function from the sheet I hope? – Siddharth Rout Sep 10 '15 at 12:32
  • Why what's the problem with calling it from the same sheet? – Jeff Palson Sep 10 '15 at 12:35
  • 6
    You cannot update other cells barring a few exceptions such as [These](http://stackoverflow.com/questions/23433096/using-a-udf-in-excel-to-update-the-worksheet). You may want to see [This](https://support.microsoft.com/en-us/kb/170787) – Siddharth Rout Sep 10 '15 at 12:38
  • Thanks man, I didn't know about this. – Jeff Palson Sep 10 '15 at 12:44
  • I'd re-think the structure: Use a sub that takes arguments, and have public variables that hold the return values from the sub. Then you can still manipulate the workbook environment. – SierraOscar Sep 10 '15 at 12:51

0 Answers0