Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Code works on sheet but not from code-to-sheet

The first line of code works fine.
The commented out line to return "" produces error 400.

Also, is it possible to do the "value = value" on the commented out code so there are no formulas in A1:A5, just the returned values?

Thanks,
Howard

Option Explicit
Sub X()
Range("A1:A5").Formula = "=VLOOKUP(C1, $D$1:$F$5, 3, 0)"

'Formula here works in sheet but not by code
'Range("A1:A5").Formula = "=IF(VLOOKUP(C1,$D$1:$F$5,3,0)=0,"",(VLOOKUP(C1,$D $1:$F$5,3,0)))"

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Code works on sheet but not from code-to-sheet

Howard,

Try this:

Sub X()

With Range("A1:A5")
.Formula = "=IF(VLOOKUP(C1,$D$1:$F$5,3,0)=0,"""", VLOOKUP(C1,$D$1:$F$5,3,0)))"
.Value = .Value
End With

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Code works on sheet but not from code-to-sheet

On Tuesday, June 4, 2013 7:29:10 PM UTC-7, Ben McClave wrote:
Howard,



Try this:



Sub X()



With Range("A1:A5")

.Formula = "=IF(VLOOKUP(C1,$D$1:$F$5,3,0)=0,"""", VLOOKUP(C1,$D$1:$F$5,3,0)))"

.Value = .Value

End With



End Sub


Thanks, Ben. Works smack on, just had to add the missing "(".

.Formula = "=IF(VLOOKUP(C1,$D$1:$F$5,3,0)=0,"""",(VLOOKUP(C1, $D$1:$F$5,3,0)))"

Regards,
Howard
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display one sheet or two userforms while code is vba code is runningon another RJQMAN[_2_] Excel Programming 2 December 30th 09 12:15 AM
Code to change code in a sheet and workbook module Otto Moehrbach Excel Programming 11 November 11th 07 07:20 PM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Code Only works when sheet is in focus Andibevan[_4_] Excel Programming 7 September 26th 05 04:06 PM
excel - macro code to open a protected sheet, enter passowrd, and then protect sheet arunjoshi[_5_] Excel Programming 1 May 2nd 04 03:50 PM


All times are GMT +1. The time now is 01:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"