Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
AK AK is offline
external usenet poster
 
Posts: 56
Default VLOOKUP formula

Dear Helper,
I have the following script to add a formular to a cell in all the sheets in
Workbook(final_bk) and copy down to the last used cells in the respective
sheet.

The script stop at vLookup line, how should I set the formula ?

For Each sh In Workbooks(final_bk).Worksheets
sh.Activate
If sh.Name < "Summary" Then
ActiveSheet.UsedRange.Select
numcolumns = Selection.Columns.Count
numRows = Selection.Rows.Count

Cells(2, numcolumns + 1).Formula =
"=IF(A2<"",VLOOKUP(A2,[WORKBOOKS(source_book)]sheets("Source")!$A:$B,2,false)"
Cells(2, numcolumns + 1).AutoFill Destination:=Range("")
Columns(numcolumns + 1).Copy
Columns(numcolumns + 1).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Next sh

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default VLOOKUP formula

All quotes within quotes (that is, all quotes in your worksheet formula)
should be entered as two quotes.

--
Kind regards,

Niek Otten

"ak" wrote in message
...
Dear Helper,
I have the following script to add a formular to a cell in all the sheets
in
Workbook(final_bk) and copy down to the last used cells in the respective
sheet.

The script stop at vLookup line, how should I set the formula ?

For Each sh In Workbooks(final_bk).Worksheets
sh.Activate
If sh.Name < "Summary" Then
ActiveSheet.UsedRange.Select
numcolumns = Selection.Columns.Count
numRows = Selection.Rows.Count

Cells(2, numcolumns + 1).Formula =
"=IF(A2<"",VLOOKUP(A2,[WORKBOOKS(source_book)]sheets("Source")!$A:$B,2,false)"
Cells(2, numcolumns + 1).AutoFill Destination:=Range("")
Columns(numcolumns + 1).Copy
Columns(numcolumns + 1).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Next sh



  #3   Report Post  
Posted to microsoft.public.excel.programming
AK AK is offline
external usenet poster
 
Posts: 56
Default VLOOKUP formula

Thanks Niek
I tried but still received error.
The error code is "1004"

"Niek Otten" 來函:

All quotes within quotes (that is, all quotes in your worksheet formula)
should be entered as two quotes.

--
Kind regards,

Niek Otten

"ak" wrote in message
...
Dear Helper,
I have the following script to add a formular to a cell in all the sheets
in
Workbook(final_bk) and copy down to the last used cells in the respective
sheet.

The script stop at vLookup line, how should I set the formula ?

For Each sh In Workbooks(final_bk).Worksheets
sh.Activate
If sh.Name < "Summary" Then
ActiveSheet.UsedRange.Select
numcolumns = Selection.Columns.Count
numRows = Selection.Rows.Count

Cells(2, numcolumns + 1).Formula =
"=IF(A2<"",VLOOKUP(A2,[WORKBOOKS(source_book)]sheets("Source")!$A:$B,2,false)"
Cells(2, numcolumns + 1).AutoFill Destination:=Range("")
Columns(numcolumns + 1).Copy
Columns(numcolumns + 1).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Next sh




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

This line actually places the formula in the cell:

Cells(2, numcolumns + 1).Formula = _
"=IF(A2<"",VLOOKUP(A2,[WORKBOOKS(source_book)]sheets("Source")!$A:$B,2,false)"

But that's not the correct syntax for the formula--you wouldn't write that
formula in a cell and expect it to work.

I like to let excel do the work for me:

dim TableRng as range
.....
set tablerng = workbooks(source_book).worksheets("source").range( "a:b")

.....

cells(2,numcolumns + 1).formula = _
"=if(a2="""","""",vlookup(a2," _
& tablerng.address(external:=true) _
& ",2,false)"

Watch your double quotes, too.



ak wrote:

Dear Helper,
I have the following script to add a formular to a cell in all the sheets in
Workbook(final_bk) and copy down to the last used cells in the respective
sheet.

The script stop at vLookup line, how should I set the formula ?

For Each sh In Workbooks(final_bk).Worksheets
sh.Activate
If sh.Name < "Summary" Then
ActiveSheet.UsedRange.Select
numcolumns = Selection.Columns.Count
numRows = Selection.Rows.Count

Cells(2, numcolumns + 1).Formula =
"=IF(A2<"",VLOOKUP(A2,[WORKBOOKS(source_book)]sheets("Source")!$A:$B,2,false)"
Cells(2, numcolumns + 1).AutoFill Destination:=Range("")
Columns(numcolumns + 1).Copy
Columns(numcolumns + 1).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Next sh


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
AK AK is offline
external usenet poster
 
Posts: 56
Default VLOOKUP formula

Hi Dave,

I tried to amend the formula as advised but same error.
Will there be problem if I use excel2000?

Tks.
Alice

"Dave Peterson" wrote:

This line actually places the formula in the cell:

Cells(2, numcolumns + 1).Formula = _
"=IF(A2<"",VLOOKUP(A2,[WORKBOOKS(source_book)]sheets("Source")!$A:$B,2,false)"

But that's not the correct syntax for the formula--you wouldn't write that
formula in a cell and expect it to work.

I like to let excel do the work for me:

dim TableRng as range
.....
set tablerng = workbooks(source_book).worksheets("source").range( "a:b")

.....

cells(2,numcolumns + 1).formula = _
"=if(a2="""","""",vlookup(a2," _
& tablerng.address(external:=true) _
& ",2,false)"

Watch your double quotes, too.



ak wrote:

Dear Helper,
I have the following script to add a formular to a cell in all the sheets in
Workbook(final_bk) and copy down to the last used cells in the respective
sheet.

The script stop at vLookup line, how should I set the formula ?

For Each sh In Workbooks(final_bk).Worksheets
sh.Activate
If sh.Name < "Summary" Then
ActiveSheet.UsedRange.Select
numcolumns = Selection.Columns.Count
numRows = Selection.Rows.Count

Cells(2, numcolumns + 1).Formula =
"=IF(A2<"",VLOOKUP(A2,[WORKBOOKS(source_book)]sheets("Source")!$A:$B,2,false)"
Cells(2, numcolumns + 1).AutoFill Destination:=Range("")
Columns(numcolumns + 1).Copy
Columns(numcolumns + 1).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Next sh


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VLOOKUP formula

The formula should work in xl2k, also.

What did you use?

ak wrote:

Hi Dave,

I tried to amend the formula as advised but same error.
Will there be problem if I use excel2000?

Tks.
Alice

"Dave Peterson" wrote:

This line actually places the formula in the cell:

Cells(2, numcolumns + 1).Formula = _
"=IF(A2<"",VLOOKUP(A2,[WORKBOOKS(source_book)]sheets("Source")!$A:$B,2,false)"

But that's not the correct syntax for the formula--you wouldn't write that
formula in a cell and expect it to work.

I like to let excel do the work for me:

dim TableRng as range
.....
set tablerng = workbooks(source_book).worksheets("source").range( "a:b")

.....

cells(2,numcolumns + 1).formula = _
"=if(a2="""","""",vlookup(a2," _
& tablerng.address(external:=true) _
& ",2,false)"

Watch your double quotes, too.



ak wrote:

Dear Helper,
I have the following script to add a formular to a cell in all the sheets in
Workbook(final_bk) and copy down to the last used cells in the respective
sheet.

The script stop at vLookup line, how should I set the formula ?

For Each sh In Workbooks(final_bk).Worksheets
sh.Activate
If sh.Name < "Summary" Then
ActiveSheet.UsedRange.Select
numcolumns = Selection.Columns.Count
numRows = Selection.Rows.Count

Cells(2, numcolumns + 1).Formula =
"=IF(A2<"",VLOOKUP(A2,[WORKBOOKS(source_book)]sheets("Source")!$A:$B,2,false)"
Cells(2, numcolumns + 1).AutoFill Destination:=Range("")
Columns(numcolumns + 1).Copy
Columns(numcolumns + 1).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Next sh


--

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
How do I combine a VLOOKUP formula and a NETWORKDAYS formula? Tracy Excel Worksheet Functions 2 October 15th 09 04:14 PM
Alternative formula to the vlookup formula? Victor Excel Worksheet Functions 2 May 12th 08 04:38 PM
convert vlookup formula to link formula AFA Excel Worksheet Functions 0 February 20th 08 04:24 AM
Excel 2002 VLOOKUP formula or other formula Serge Excel Discussion (Misc queries) 4 February 26th 07 03:56 PM
VLookup Formula jazzydwit Excel Worksheet Functions 6 July 10th 06 06:04 PM


All times are GMT +1. The time now is 07:04 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"