View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
ShaneDevenshire ShaneDevenshire is offline
external usenet poster
 
Posts: 2,344
Default Can't get my "'s Right - Never !!

Hi,

There is really nothing wrong with the first formula, although I have
simplified them slightly.
To correct the second formula use:

With target
.Offset(0, -1) = "=row()-2"
.Offset(0, 1) = "=Vlookup(B" & .Row & ",Sheet2!$A$1:$B$7,2,False)"
End With

In general quotes are like parentheses - there should be an equal number.
In this case you want to make the .Row argument a vba variable so it must be
outside the quoted text otherwise it is taken literally. This means that you
will need an " & vbaVariable & " type of layout. You got half of it.

As for single quotes, these often appear around path references, especially
those that contain names with spaces. The easiest way to handle them is to
record the code. In fact that is the easiest way to start entering your
formulas in code - record them, and then modify them.

The idea of having a equal number of quotes (single or double) is a general
rule which may not always hold. For example if your formula is looking for a
' in a string then the single quote might appear once.

--
Cheers,
Shane Devenshire


"JMay" wrote:

I always BOMB when trying to UNDERSTAND How to place the " 's and the & 's
when stringing together say line 3 below. Can someone assist?

With Target
.Offset(0, -1).Formula = "=row()-2"
.Offset(0, 1).Formula = "=Vlookup(B"&target.row,Sheet2!$A$1:$B$7,2,Fal se)"
End With

TIA,

Jim