Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 484
  • 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

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.

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