Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 39
Default Formulas change when macro adds new column

Spreadsheet has formulas that pick up values from data tab. Macro inserts a
new column B in the data tab. When it does that, the formulas move from B:C
to C:D. The formula is in a vlookup. How do I get the formula to stay as
B:C. I tried INDIRECT but it does not work in VLOOKUP. Any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,510
Default Formulas change when macro adds new column

Hi Sandra,

As you are using a macro to insert the column you can initially name the
range B:C on the worksheet (See 'define name' in the worksheet help) and then
use the named range in the formula like the following (I have named the range
'MyLookUpRng':-

=VLOOKUP(B1,MyLookUpRng,2,FALSE)

Then in the macro after inserting the column rename columns B:C to the named
range like the following (Note C2:C3 is columns 2 and 3):-

Sheets("Data").Columns("B:B").Insert Shift:=xlToRight

ActiveWorkbook.Names.Add Name:="MyLookUpRng", _
RefersToR1C1:="=Data!C2:C3"

--
Regards,

OssieMac


"Sandra" wrote:

Spreadsheet has formulas that pick up values from data tab. Macro inserts a
new column B in the data tab. When it does that, the formulas move from B:C
to C:D. The formula is in a vlookup. How do I get the formula to stay as
B:C. I tried INDIRECT but it does not work in VLOOKUP. Any ideas?

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 39
Default Formulas change when macro adds new column

I will try that. Thank you.

"OssieMac" wrote:

Hi Sandra,

As you are using a macro to insert the column you can initially name the
range B:C on the worksheet (See 'define name' in the worksheet help) and then
use the named range in the formula like the following (I have named the range
'MyLookUpRng':-

=VLOOKUP(B1,MyLookUpRng,2,FALSE)

Then in the macro after inserting the column rename columns B:C to the named
range like the following (Note C2:C3 is columns 2 and 3):-

Sheets("Data").Columns("B:B").Insert Shift:=xlToRight

ActiveWorkbook.Names.Add Name:="MyLookUpRng", _
RefersToR1C1:="=Data!C2:C3"

--
Regards,

OssieMac


"Sandra" wrote:

Spreadsheet has formulas that pick up values from data tab. Macro inserts a
new column B in the data tab. When it does that, the formulas move from B:C
to C:D. The formula is in a vlookup. How do I get the formula to stay as
B:C. I tried INDIRECT but it does not work in VLOOKUP. Any ideas?

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,073
Default Formulas change when macro adds new column

On Jan 24, 7:44*am, Sandra wrote:
*Spreadsheet has formulas that pick up values from data tab. *Macro inserts a
new column B in the data tab. *When it does that, the formulas move from B:C
to C:D. *The formula is in a vlookup. *How do I get the formula to stay as
B:C. *I tried INDIRECT but it does not work in VLOOKUP. *Any ideas?


INDIRECT works in VLOOKUP for me, eg...

=VLOOKUP(A1,INDIRECT("C1:D6"),2,0)

Ken Johnson
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
conditional change of column reference in formulas excel help acct[_2_] Excel Discussion (Misc queries) 1 January 12th 08 01:39 AM
How to change column letters to correct ones in many formulas automatically? Dmitry Kopnichev Links and Linking in Excel 7 October 13th 05 09:52 PM
How to change column letters to correct ones in many formulas automatically? Dmitry Kopnichev Excel Worksheet Functions 7 October 13th 05 09:52 PM
Is there a macro which adds selected/highlighted cells? Ed Excel Worksheet Functions 2 September 28th 05 01:36 PM
Looping Macro That adds a blank row between different part #'s fiero84 Excel Discussion (Misc queries) 5 March 25th 05 06:59 AM


All times are GMT +1. The time now is 05:36 AM.

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"