Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 124
Default Find and replace cell values Macro

Hello, I am looking for some help creating a macro for find/replace.

What I am looking to do is look at a cell say A1, take the values in the
cell, and use it to replace "X" in a vlookup.

For example

A1 = 5

replace

=vlookup(c1,"Sheet X",A:D,2,false)

Thank you in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Find and replace cell values Macro

Hi ryan,

Hope I have interpreted your question correctly.

Note:- The space and underscore at the end of a line is a line break in an
otherwise single line of code. You may know this but in case you don't,
telling you now saves confusing you.

Sub InsertFormula()

Dim createFormula As Variant

'Assumes cell A1 on Sheet1 contains the required sheet number

createFormula = "=VLOOKUP(C1,Sheet" & _
Sheets("Sheet1").Range("A1") & "!A1:D250,2,FALSE)"

'Insert the formula in cell B1 on sheet 1
Sheets("Sheet1").Range("B1") = createFormula

End Sub


Sub InsertFormula2()
'Alternative method without using variable

Sheets("Sheet1").Range("B1") = "=VLOOKUP(C1,Sheet" & _
Sheets("Sheet1").Range("A1") & "!A1:D250,2,FALSE)"

End Sub

--

Regards,

OssieMac


"Ryan" wrote:

Hello, I am looking for some help creating a macro for find/replace.

What I am looking to do is look at a cell say A1, take the values in the
cell, and use it to replace "X" in a vlookup.

For example

A1 = 5

replace

=vlookup(c1,"Sheet X",A:D,2,false)

Thank you in advance.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Find and replace cell values Macro

Hi again Ryan,

I just realized that you used the column references A:D only without the row
numbers for the Lookup Range. You can use that in lieu of the range that I
used.
--
Regards,

OssieMac


"OssieMac" wrote:

Hi ryan,

Hope I have interpreted your question correctly.

Note:- The space and underscore at the end of a line is a line break in an
otherwise single line of code. You may know this but in case you don't,
telling you now saves confusing you.

Sub InsertFormula()

Dim createFormula As Variant

'Assumes cell A1 on Sheet1 contains the required sheet number

createFormula = "=VLOOKUP(C1,Sheet" & _
Sheets("Sheet1").Range("A1") & "!A1:D250,2,FALSE)"

'Insert the formula in cell B1 on sheet 1
Sheets("Sheet1").Range("B1") = createFormula

End Sub


Sub InsertFormula2()
'Alternative method without using variable

Sheets("Sheet1").Range("B1") = "=VLOOKUP(C1,Sheet" & _
Sheets("Sheet1").Range("A1") & "!A1:D250,2,FALSE)"

End Sub

--

Regards,

OssieMac


"Ryan" wrote:

Hello, I am looking for some help creating a macro for find/replace.

What I am looking to do is look at a cell say A1, take the values in the
cell, and use it to replace "X" in a vlookup.

For example

A1 = 5

replace

=vlookup(c1,"Sheet X",A:D,2,false)

Thank you in advance.

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
Find and Replace Cell Values Jeff Excel Discussion (Misc queries) 3 March 23rd 10 01:46 PM
Macro to find and replace using cell references edeaston Excel Discussion (Misc queries) 1 December 22nd 08 03:29 PM
Using a cell reference within a macro to find and replace McCloudK Excel Discussion (Misc queries) 1 September 17th 07 07:04 PM
Using Find and Replace to replace " in a macro snail30152 Excel Programming 1 April 13th 06 11:58 PM
Find and replace thousand of cell values Tom Ogilvy Excel Programming 1 May 6th 04 08:56 AM


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

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"