• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 486
  • Last Modified:

excel vba syntax dsum comparison with variable

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
Not2ruthless
Asked:
Not2ruthless
1 Solution
 
SteveCommented:
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
 
Rgonzo1971Commented:
Hi,

With Chr, it's easier

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

Regards
0
 
Not2ruthlessAuthor Commented:
Thank you both.  I think I had nightmares that included quote marks!
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now