# Create a vba formula from cells

This is a discussion on Create a vba formula from cells within the Excel Questions forums, part of the Question Forums category; Need a little assistance with a vba formula to get info from cells to create a formula like this Code: ...

1. ## Create a vba formula from cells

Need a little assistance with a vba formula to get info from cells to create a formula like this
Code:
```    Range("J1").Formula = "=IF(D1=""Mayberry R.F.D."",""Mayberry RFD""," & _
"IF(D1=""Diners, Drive-ins and Dives"",""Diners Drive-Ins and Dives"",IF(D1=""Forever "",""Forever (2014)""," & _
"IF(D1=""Food Factory (CA)"",""Food Factory CA"",IF(D1=""Castle (2009)"",""Castle 2009"",IF(D1=""Guy's Grocery Games"",""Guys Grocery Games"",D1))))))"

Range("J1").Copy
Range("J2:J" & LastRow).Select
ActiveSheet.Paste
Application.CutCopyMode = False```
I am constantly adding to the formula.
So, say column A would be what to look for, column B what to change to to.

Thanks

2. ## Re: Create a vba formula from cells

Try this...

Code:
`Range("J1:J" & LastRow).Formula = "=IFERROR(VLOOKUP(D1,A:B,2,0),"""")"`

3. ## Re: Create a vba formula from cells

Originally Posted by AlphaFrog
Try this...

Code:
`Range("J1:J" & LastRow).Formula = "=IFERROR(VLOOKUP(D1,A:B,2,0),"""")"`
Thank you, I will give that a try!

4. ## Re: Create a vba formula from cells

Originally Posted by camle
Thank you, I will give that a try!
If I put all the data in another worksheet, say "Changes" How pick up the sheet name.

5. ## Re: Create a vba formula from cells

Originally Posted by camle
If I put all the data in another worksheet, say "Changes" How pick up the sheet name.
Code:
`Range("J1:J" & LastRow).Formula = "=IFERROR(VLOOKUP(D1,Changes!A:B,2,0),"""")"`

6. ## Re: Create a vba formula from cells

Originally Posted by AlphaFrog
Code:
`Range("J1:J" & LastRow).Formula = "=IFERROR(VLOOKUP(D1,Changes!A:B,2,0),"""")"`
if D1 does not need the change then make it D1

Thanks

7. ## Re: Create a vba formula from cells

Originally Posted by camle
if D1 does not need the change then make it D1

Thanks
Code:
`Range("J1:J" & LastRow).Formula = "=IFERROR(VLOOKUP(D1,Changes!A:B,2,0),D1)"`

8. ## Re: Create a vba formula from cells

Originally Posted by camle
if D1 does not need the change then make it D1

Thanks
OK Brain on

Code:
`=IFERROR(VLOOKUP(D2,Changes!A:B,2,0),D1)`

9. ## Re: Create a vba formula from cells

Originally Posted by camle
OK Brain on

Code:
`=IFERROR(VLOOKUP(D2,Changes!A:B,2,0),D1)`
Sometimes things are just over thought.
Very good solution that you have there.

Thanks

10. ## Re: Create a vba formula from cells

You're welcome. Thanks for the feedback.

You mixed D2 and D1 in the formaula?
=IFERROR(VLOOKUP(D2,Changes!A:B,2,0),D1)

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•