Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 468
Default Can't get my "'s Right - Never !!

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 171
Default Can't get my "'s Right - Never !!

For starters, you'll probably always have an even number of "s; whatever
literal string you open must get closed.
Next, whenever you drop in an expression to be evaluated within part of a
string, it will likely need the & before and after.
If you are in the VB editor (esp in break mode, with target.row having a
legit value), you can enter a question mark and then the expression in the
Immediate window; you need the result to look exactly like your formula
should.
"=Vlookup(B" & target.row & ",Sheet2!$A$1:$B$7,2,False)"

"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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default Can't get my "'s Right - Never !!

Try this

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


Mike

"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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,393
Default Can't get my "'s Right - Never !!

I never use the .formula method but I expect you need to change the last one
to
Offset(0, 1).Formula =
"=Vlookup(indirect("B"&target.row),Sheet2!$A$1:$B$ 7,2,False)"
But how will the worksheet know about "target row"
Why not try

Offset(0, 1).Formula = "=Vlookup(indirect("B" &
ROW()-2),Sheet2!$A$1:$B$7,2,False)"

I have not tested this!
--
Bernard Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme

"JMay" wrote in message
...
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


  #5   Report Post  
Posted to microsoft.public.excel.misc
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



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Can't get my "'s Right - Never !!

And sometimes, it's just easier to use R1C1 reference style:

.Offset(0, 1).FormulaR1C1 = "=Vlookup(rc2,Sheet2!r1c1:r7c2,2,False)"

rc2 means same row as the formula, but column 2 (B).

R1C1 is row 1 column 1 (A1)
r7c2 is row 7 column 2 (B7)





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


--

Dave Peterson
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
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
Complex if test program possible? If "value" "value", paste "value" in another cell? jseabold Excel Discussion (Misc queries) 1 January 30th 06 10:01 PM
Insert "-" in text "1234567890" to have a output like this"123-456-7890" Alwyn Excel Discussion (Misc queries) 3 October 25th 05 11:36 PM


All times are GMT +1. The time now is 05:20 PM.

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

About Us

"It's about Microsoft Excel"