Solved

excel vba syntax dsum comparison with variable

Posted on 2013-01-24
3
434 Views
Last Modified: 2013-01-25
Hello.  I am trying, via Excel VBA to change a DSUM equality comparison utilizing a string variable.  For instance, here is the current comparison.


="=Supplies"

Upon copying a new column I'd like the code to replace "Supplies" with a string variable named NewCategory. .

for example,
dim sNewCategory as string
sNewCategory = "Rent"


activecell.formula = "="" & NewCategory & """

Obviously, that example is wrong wrong wrong.  I cannot figure out where to put the quotes at all.

Any help greatly appreciated and will speed up my current find/replace code that makes me nervous :)

Thanks!
0
Comment
Question by:Not2ruthless
3 Comments
 
LVL 24

Expert Comment

by:Steve
ID: 38817690
Here you go:

Dim sNewCategory As String
sNewCategory = "Rent"

ActiveCell.Formula = "=""=" & sNewCategory & """"

Open in new window


Please note that you may find SUMIFS can likely do the job of DSUM "better"
0
 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 120 total points
ID: 38817711
Hi,

With Chr, it's easier

ActiveCell.Formula = "=" & Chr(34) & "=" & NewCategory & Chr(34)

Regards
0
 

Author Closing Comment

by:Not2ruthless
ID: 38818669
Thank you both.  I think I had nightmares that included quote marks!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Many companies are making the switch from Microsoft to Google Apps (https://www.google.com/work/apps/business/). Use this article to learn more about what Google Apps has to offer and to help if you’re planning on migrating to Google Apps. It is …
User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now