Solved

excel vba syntax dsum comparison with variable

Posted on 2013-01-24
3
446 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 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

867 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

19 Experts available now in Live!

Get 1:1 Help Now