Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

excel vba syntax dsum comparison with variable

Posted on 2013-01-24
3
Medium Priority
?
480 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 52

Accepted Solution

by:
Rgonzo1971 earned 480 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

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…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

722 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