View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
George
 
Posts: n/a
Default Getting wrong value due to ref?

You have missed a few quote marks (after Sheet2 and B5:E5)
And you dont need the A1:D1 just the A1,
Excel will adjust the formula as it copies across

Try this:
Sheets("Sheet2").Range("B5:E5").Value = _
"=If('Sheet1'!A1="""",0,'Sheet1'!A1)"

George

jesmin wrote:
Hi Anyone:
I have 2 worksheets.

I wrote down in VB:
Sheets("Sheet2).Range("B5:E5).Value
="=If('Sheet1'!A1:D1="""",0,'Sheet1'!A1:D1)"

--Why the code is giving wrong results.

Thanks a lot for any help.