Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Reference Cell in VLOOKUP

When I use ($A" & NewRow2... like you suggest I get an error [end of
statement expected]. I even tried ("$A" & NewRow2... I also tried (""$A"" &
NewRow2... which did put the formula in the spreadsheet but it printed like
this ($A & NewRow2... so the code didn't interpret the variable, it just
printed the variable name. What am I doing wrong?

"Dave Peterson" wrote:

I didn't notice that you were putting the formula in a single cell.

You can use:
..range("z" & newrow2).formula = _
or
..cells(newrow2,"Z").formula = _
instead of:
..Range("Z" & NewRow2 & ":Z" & NewRow2).Formula = _

It makes it a little easier to read.

NewRow2 = 6
With Worksheets("Sheet1")
For RowCount = Start To NewRow
If NewRow2 < NewRow Then
.Range("Z" & NewRow2).Formula = _
"=IF(ISNA(VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),11,FALSE)),""""," _
& "VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),11,FALSE))"

.Range("AA" & NewRow2).Formula = _
"=IF(ISNA(VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),6,FALSE)),""""," _
& "VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),6,FALSE))"

.Range("Z" & NewRow2 & ":AA" & NewRow2 + 4).FillDown
NewRow2 = NewRow2 + 8
End If
Next RowCount
End With

And I didn't see a response to the other thread (yet??), but remember when you
use =indirect(), the sending workbook has to be open.

Bishop wrote:

Here's my code snippet:

NewRow2 = 6
For RowCount = Start To NewRow
If NewRow2 < NewRow Then
.Range("Z" & NewRow2 & ":Z" & NewRow2).Formula = _

"=IF(ISNA(VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),11,FALSE)),"""", " & _

"VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),11,FALSE))"
.Range("AA" & NewRow2 & ":AA" & NewRow2).Formula = _

"=IF(ISNA(VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),6,FALSE)),""""," & _

"VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),6,FALSE))"
.Range("Z" & NewRow2 & ":AA" & (NewRow2 + 4)).FillDown
NewRow2 = NewRow2 + 8
End If
Next RowCount

The first run through this code puts the formulas in Z6 and AA6 and fills
down to Z10 and AA10. Which is what I want. After "NewRow2 = NewRow2 + 8"
NewRow2 is now 14. Again, this is correct. The problem is I have $A6 in my
VLOOKUP formula so, on the second pass, the formulas are place in Z14 and
AA14, as they should, but my VLOOKUP formula still has $A6 and I need it to
have $A14. How do I make that change like it does in my .Range?


--

Dave Peterson

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Reference Cell in VLOOKUP

Did you retype my suggestion or did you copy|paste?

I'm betting that you changed something else.



Bishop wrote:

When I use ($A" & NewRow2... like you suggest I get an error [end of
statement expected]. I even tried ("$A" & NewRow2... I also tried (""$A"" &
NewRow2... which did put the formula in the spreadsheet but it printed like
this ($A & NewRow2... so the code didn't interpret the variable, it just
printed the variable name. What am I doing wrong?

"Dave Peterson" wrote:

I didn't notice that you were putting the formula in a single cell.

You can use:
..range("z" & newrow2).formula = _
or
..cells(newrow2,"Z").formula = _
instead of:
..Range("Z" & NewRow2 & ":Z" & NewRow2).Formula = _

It makes it a little easier to read.

NewRow2 = 6
With Worksheets("Sheet1")
For RowCount = Start To NewRow
If NewRow2 < NewRow Then
.Range("Z" & NewRow2).Formula = _
"=IF(ISNA(VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),11,FALSE)),""""," _
& "VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),11,FALSE))"

.Range("AA" & NewRow2).Formula = _
"=IF(ISNA(VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),6,FALSE)),""""," _
& "VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),6,FALSE))"

.Range("Z" & NewRow2 & ":AA" & NewRow2 + 4).FillDown
NewRow2 = NewRow2 + 8
End If
Next RowCount
End With

And I didn't see a response to the other thread (yet??), but remember when you
use =indirect(), the sending workbook has to be open.

Bishop wrote:

Here's my code snippet:

NewRow2 = 6
For RowCount = Start To NewRow
If NewRow2 < NewRow Then
.Range("Z" & NewRow2 & ":Z" & NewRow2).Formula = _

"=IF(ISNA(VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),11,FALSE)),"""", " & _

"VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),11,FALSE))"
.Range("AA" & NewRow2 & ":AA" & NewRow2).Formula = _

"=IF(ISNA(VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),6,FALSE)),""""," & _

"VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),6,FALSE))"
.Range("Z" & NewRow2 & ":AA" & (NewRow2 + 4)).FillDown
NewRow2 = NewRow2 + 8
End If
Next RowCount

The first run through this code puts the formulas in Z6 and AA6 and fills
down to Z10 and AA10. Which is what I want. After "NewRow2 = NewRow2 + 8"
NewRow2 is now 14. Again, this is correct. The problem is I have $A6 in my
VLOOKUP formula so, on the second pass, the formulas are place in Z14 and
AA14, as they should, but my VLOOKUP formula still has $A6 and I need it to
have $A14. How do I make that change like it does in my .Range?


--

Dave Peterson


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 208
Default Reference Cell in VLOOKUP

I didn't copy|paste until this morning. I merely changed the part I
originally asked you about ($A" & NewRow2...). I went back and copy|pasted
like you suggested and sure enough it works. I went back and tried to find
the descrepencey but couldn't. Your use of the & makes the code look better
anyway. Just out of curiosity what else did you change?

"Dave Peterson" wrote:

Did you retype my suggestion or did you copy|paste?

I'm betting that you changed something else.



Bishop wrote:

When I use ($A" & NewRow2... like you suggest I get an error [end of
statement expected]. I even tried ("$A" & NewRow2... I also tried (""$A"" &
NewRow2... which did put the formula in the spreadsheet but it printed like
this ($A & NewRow2... so the code didn't interpret the variable, it just
printed the variable name. What am I doing wrong?

"Dave Peterson" wrote:

I didn't notice that you were putting the formula in a single cell.

You can use:
..range("z" & newrow2).formula = _
or
..cells(newrow2,"Z").formula = _
instead of:
..Range("Z" & NewRow2 & ":Z" & NewRow2).Formula = _

It makes it a little easier to read.

NewRow2 = 6
With Worksheets("Sheet1")
For RowCount = Start To NewRow
If NewRow2 < NewRow Then
.Range("Z" & NewRow2).Formula = _
"=IF(ISNA(VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),11,FALSE)),""""," _
& "VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),11,FALSE))"

.Range("AA" & NewRow2).Formula = _
"=IF(ISNA(VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),6,FALSE)),""""," _
& "VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),6,FALSE))"

.Range("Z" & NewRow2 & ":AA" & NewRow2 + 4).FillDown
NewRow2 = NewRow2 + 8
End If
Next RowCount
End With

And I didn't see a response to the other thread (yet??), but remember when you
use =indirect(), the sending workbook has to be open.

Bishop wrote:

Here's my code snippet:

NewRow2 = 6
For RowCount = Start To NewRow
If NewRow2 < NewRow Then
.Range("Z" & NewRow2 & ":Z" & NewRow2).Formula = _

"=IF(ISNA(VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),11,FALSE)),"""", " & _

"VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),11,FALSE))"
.Range("AA" & NewRow2 & ":AA" & NewRow2).Formula = _

"=IF(ISNA(VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),6,FALSE)),""""," & _

"VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),6,FALSE))"
.Range("Z" & NewRow2 & ":AA" & (NewRow2 + 4)).FillDown
NewRow2 = NewRow2 + 8
End If
Next RowCount

The first run through this code puts the formulas in Z6 and AA6 and fills
down to Z10 and AA10. Which is what I want. After "NewRow2 = NewRow2 + 8"
NewRow2 is now 14. Again, this is correct. The problem is I have $A6 in my
VLOOKUP formula so, on the second pass, the formulas are place in Z14 and
AA14, as they should, but my VLOOKUP formula still has $A6 and I need it to
have $A14. How do I make that change like it does in my .Range?

--

Dave Peterson


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Reference Cell in VLOOKUP

I don't recall.

But you could compare them as well as I could.

Bishop wrote:

I didn't copy|paste until this morning. I merely changed the part I
originally asked you about ($A" & NewRow2...). I went back and copy|pasted
like you suggested and sure enough it works. I went back and tried to find
the descrepencey but couldn't. Your use of the & makes the code look better
anyway. Just out of curiosity what else did you change?

"Dave Peterson" wrote:

Did you retype my suggestion or did you copy|paste?

I'm betting that you changed something else.



Bishop wrote:

When I use ($A" & NewRow2... like you suggest I get an error [end of
statement expected]. I even tried ("$A" & NewRow2... I also tried (""$A"" &
NewRow2... which did put the formula in the spreadsheet but it printed like
this ($A & NewRow2... so the code didn't interpret the variable, it just
printed the variable name. What am I doing wrong?

"Dave Peterson" wrote:

I didn't notice that you were putting the formula in a single cell.

You can use:
..range("z" & newrow2).formula = _
or
..cells(newrow2,"Z").formula = _
instead of:
..Range("Z" & NewRow2 & ":Z" & NewRow2).Formula = _

It makes it a little easier to read.

NewRow2 = 6
With Worksheets("Sheet1")
For RowCount = Start To NewRow
If NewRow2 < NewRow Then
.Range("Z" & NewRow2).Formula = _
"=IF(ISNA(VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),11,FALSE)),""""," _
& "VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),11,FALSE))"

.Range("AA" & NewRow2).Formula = _
"=IF(ISNA(VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),6,FALSE)),""""," _
& "VLOOKUP($A" & NewRow2 _
& ",INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'" _
& "!$F$1:$P$5000""),6,FALSE))"

.Range("Z" & NewRow2 & ":AA" & NewRow2 + 4).FillDown
NewRow2 = NewRow2 + 8
End If
Next RowCount
End With

And I didn't see a response to the other thread (yet??), but remember when you
use =indirect(), the sending workbook has to be open.

Bishop wrote:

Here's my code snippet:

NewRow2 = 6
For RowCount = Start To NewRow
If NewRow2 < NewRow Then
.Range("Z" & NewRow2 & ":Z" & NewRow2).Formula = _

"=IF(ISNA(VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),11,FALSE)),"""", " & _

"VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),11,FALSE))"
.Range("AA" & NewRow2 & ":AA" & NewRow2).Formula = _

"=IF(ISNA(VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),6,FALSE)),""""," & _

"VLOOKUP($A6,INDIRECT(""'[""&$Y$2&""]By_Rep_by_Filter'!$F$1:$P$5000""),6,FALSE))"
.Range("Z" & NewRow2 & ":AA" & (NewRow2 + 4)).FillDown
NewRow2 = NewRow2 + 8
End If
Next RowCount

The first run through this code puts the formulas in Z6 and AA6 and fills
down to Z10 and AA10. Which is what I want. After "NewRow2 = NewRow2 + 8"
NewRow2 is now 14. Again, this is correct. The problem is I have $A6 in my
VLOOKUP formula so, on the second pass, the formulas are place in Z14 and
AA14, as they should, but my VLOOKUP formula still has $A6 and I need it to
have $A14. How do I make that change like it does in my .Range?

--

Dave Peterson


--

Dave Peterson


--

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
Vlookup cell reference Johno Excel Discussion (Misc queries) 6 September 18th 09 01:56 PM
vlookup cell reference KJ Excel Discussion (Misc queries) 2 January 17th 08 10:35 PM
VLookup and a Cell Reference Karen53 Excel Worksheet Functions 3 August 29th 07 09:43 PM
VLOOKUP using cell reference Lee Harris Excel Worksheet Functions 1 August 18th 06 05:10 PM
reference vlookup cell hef[_2_] Excel Programming 1 November 7th 03 04:38 PM


All times are GMT +1. The time now is 03:40 PM.

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"