|
-
Sep 9th, 2010, 09:21 AM
#1
Thread Starter
New Member
Problem : Excel formula using VB code
Hi All,
I've got a problem with excel.
I am facing this problem while I enter formula in the excel sheet using vb code. I have selected a cell and then I use the code,
activecell.formulaR1C1 = "=vlookup(blah,blah...)"
and then I fill this formula to the desired range of cells.
What happens is....the formula is written in the cells as a text and the formula is not picking the value from the page mentioned in it.
In the excel sheet, in the desired cell (eg H1) the content remains as =vlookup(blah,blah...) instead of the value.
Can anyone help me out of this???
-
Sep 9th, 2010, 12:21 PM
#2
Addicted Member
Re: Problem : Excel formula using VB code
Welcome to the forum!
Give us a full example. "blah, blah, blah" doesn't tell us if you correctly coded the formula! Also, instead of Activecell try using a range:
Code:
Worksheets("Sheet1").Range("B1").FormulaR1C1 = <formula here>
It's just better practice to use a specific range instead of Activecell.
Another suggestion: use a different, simpler formula i.e. =SUM and see if you get the same result. For example, this works fine for me when A1 through A3 have 1,2,3 respectively, giving me a value of 6:
Code:
Worksheets("Sheet1").Range("B3").FormulaR1C1 = "=SUM(r1C1:r3C1)"
Just thought of something else, check the format of the cell. Is it "Text"? If so, formulas won't work in any cell that is "Text" format.
Sorry for the train of thought post, but I hope it helps.
-EM
---
REMEMBER: If your issue is resolved, use the Thread Tools menu to set it as such, and be sure to rate the posts that help you the most!

Just because I was jealous of g4hsean! 
-
Sep 9th, 2010, 01:28 PM
#3
Re: Problem : Excel formula using VB code
Code:
activecell.formulaR1C1 = "=vlookup(blah,blah...)"
Welcome to the forums Syan 
I guess this is what you are trying?
Code:
ActiveCell.Formula = "=vlookup(blah,blah...)"
If it still shows you the formula rather than calculating it then do the following... (Since I don't know whether you are using Excel 2003 or 2007, I am including solution for both versions)
1) Excel 2003
Click on Tool~~>Options~~>View Tab (see picture below)

Uncheck the checkbox "Formulas" under "Window options"
2) Excel 2007
Under Formula Tab, unselect the option "Show Formulas"
Hope this helps...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 9th, 2010, 06:07 PM
#4
Re: Problem : Excel formula using VB code
The cell was formatted as Text.
Change it's NumberFormat to General, it will accept formula as formula not Text.
-
Sep 10th, 2010, 05:52 AM
#5
Thread Starter
New Member
Re: Problem : Excel formula using VB code
Guys,
Thanks for your replies...
I used the formula,
Code:
activecell.formular1c1 = "=vlookup(B:B,'EMP DETAILS'!B:E,4,false)"
;;;;;;;;;;;;;;;
I even tried using
Code:
activesheet.range("H3").value = application.worksheetfunction.vlookup([B3],worksheet("EMP DETAILS").range("B:E").value,4,false)
but I get an error called
unable to get the vlookup property of worksheet function.....
Actually what I am trying to do is to fill in values from a sheet into other sheet.
Is there any other possibles that you guys could suggest..
-
Sep 10th, 2010, 06:01 AM
#6
Re: Problem : Excel formula using VB code
I recommend going through Post # 3 again
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 10th, 2010, 06:05 AM
#7
Thread Starter
New Member
Re: Problem : Excel formula using VB code
koolsid,
Its already unchedked....
-
Sep 10th, 2010, 06:25 AM
#8
Thread Starter
New Member
Re: Problem : Excel formula using VB code
Even the format of the cell was "General"..
-
Sep 10th, 2010, 09:10 AM
#9
Addicted Member
Re: Problem : Excel formula using VB code
Hi Syan,
What happens when you run this:
Code:
With ActiveCell
.NumberFormat = "General"
.Formula = "=vlookup(B:B,'EMP DETAILS'!B:E,4,false)"
End With
-
Sep 10th, 2010, 09:43 AM
#10
Re: Problem : Excel formula using VB code
 Originally Posted by Syan
koolsid,
Its already unchedked....
I recommend going through Post # 3 once again
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|