Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Simple Vlookup Looping

Hi Everyone,

Cany anyone help me with writing a simple code to run every worksheet
in my workbook and do a same vlookup?


i.e.


- I have 10 different worksheets in same format (same number of
columns and rows as well)
- Lookup value is always A5 in each sheet
- Lookup range comes from different excel file called "finance.xls",
"Summary" tab column A to B


I am just trying to do 'Vlookup($A$5,'finance'A:B,2,false) in column
B
starting from row 1 to row 2200 for every worksheet.


Please help


Thank you for your help in advance.


Regards


James
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default Simple Vlookup Looping

Make a copy of your workbook to test with!

I think this should do it for you. Open the (test) workbook, press
[Alt]+[F11] to open the VB Editor, and use Insert -- Module to get a code
module to use. Copy the code below and paste it into the code module. Close
the VB Editor and then use Tools -- Macro -- Macros to [Run] it. If it
works as it did for me, then you can save the test workbook back over the
original if you want to.

Sub MakeVlookupFormulas()
Dim anySheet As Worksheet
Dim formulaRange As Range
Dim myFormula As String

myFormula = _
"=IF(ISNA(VLOOKUP($A$5,finance!$A:$B,2,FALSE)) ," & _
Chr$(34) & Chr$(34) & _
",VLOOKUP($A$5,finance!$A:$B,2,FALSE))"
'if you want to show NO MATCH situations, use this
'statement instead
'myFormula = _
"=IF(ISNA(VLOOKUP($A$5,finance!$A:$B,2,FALSE)) ," & _
Chr$(34) & "NO MATCH" & Chr$(34) & _
",VLOOKUP($A$5,finance!$A:$B,2,FALSE))"

For Each anySheet In ThisWorkbook.Worksheets
If UCase(Trim(anySheet.Name)) < "FINANCE" Then
'do this to any sheet not named like "finance"
Set formulaRange = anySheet.Range("B1:B2200")
formulaRange.Formula = myFormula
End If
Next
Set formulaRange = Nothing ' good housekeeping
MsgBox "All done now", vbOKOnly, "Task Completed"
End Sub

"James" wrote:

Hi Everyone,

Cany anyone help me with writing a simple code to run every worksheet
in my workbook and do a same vlookup?


i.e.


- I have 10 different worksheets in same format (same number of
columns and rows as well)
- Lookup value is always A5 in each sheet
- Lookup range comes from different excel file called "finance.xls",
"Summary" tab column A to B


I am just trying to do 'Vlookup($A$5,'finance'A:B,2,false) in column
B
starting from row 1 to row 2200 for every worksheet.


Please help


Thank you for your help in advance.


Regards


James
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Simple Vlookup Looping

This a quick way to get 22,000 formulas into a workbook, which seems to me
unnecessary bloat and calculation time. It appears that each worksheet only
has one answer each from the VLookup of cell $A$5. Why not find the answer
once for each sheet and assign the value to B1:B2200?

Mike F
"JLatham" wrote in message
...
Make a copy of your workbook to test with!

I think this should do it for you. Open the (test) workbook, press
[Alt]+[F11] to open the VB Editor, and use Insert -- Module to get a code
module to use. Copy the code below and paste it into the code module.
Close
the VB Editor and then use Tools -- Macro -- Macros to [Run] it. If it
works as it did for me, then you can save the test workbook back over the
original if you want to.

Sub MakeVlookupFormulas()
Dim anySheet As Worksheet
Dim formulaRange As Range
Dim myFormula As String

myFormula = _
"=IF(ISNA(VLOOKUP($A$5,finance!$A:$B,2,FALSE)) ," & _
Chr$(34) & Chr$(34) & _
",VLOOKUP($A$5,finance!$A:$B,2,FALSE))"
'if you want to show NO MATCH situations, use this
'statement instead
'myFormula = _
"=IF(ISNA(VLOOKUP($A$5,finance!$A:$B,2,FALSE)) ," & _
Chr$(34) & "NO MATCH" & Chr$(34) & _
",VLOOKUP($A$5,finance!$A:$B,2,FALSE))"

For Each anySheet In ThisWorkbook.Worksheets
If UCase(Trim(anySheet.Name)) < "FINANCE" Then
'do this to any sheet not named like "finance"
Set formulaRange = anySheet.Range("B1:B2200")
formulaRange.Formula = myFormula
End If
Next
Set formulaRange = Nothing ' good housekeeping
MsgBox "All done now", vbOKOnly, "Task Completed"
End Sub

"James" wrote:

Hi Everyone,

Cany anyone help me with writing a simple code to run every worksheet
in my workbook and do a same vlookup?


i.e.


- I have 10 different worksheets in same format (same number of
columns and rows as well)
- Lookup value is always A5 in each sheet
- Lookup range comes from different excel file called "finance.xls",
"Summary" tab column A to B


I am just trying to do 'Vlookup($A$5,'finance'A:B,2,false) in column
B
starting from row 1 to row 2200 for every worksheet.


Please help


Thank you for your help in advance.


Regards


James
.



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
simple looping question Person Excel Programming 3 December 1st 06 12:11 AM
Help with simple looping program Stephen Excel Programming 2 August 4th 06 06:55 PM
Simple looping question light Excel Programming 2 August 19th 05 09:28 PM
Simple looping question light Excel Programming 2 August 16th 05 06:30 PM
Simple Array Looping Nikky Excel Programming 2 April 20th 05 10:38 PM


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