使用VBA在一个单元格中插入公式 [英] Insert formula in one cell using VBA

查看:289
本文介绍了使用VBA在一个单元格中插入公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经被问到了,我试图复制如何在一个单元格中插入公式,但是,我的vba代码出现错误.

I know this topic was already asked and I tried to copy on how to insert a formula in one cell, however, I got an error in my vba code.

这是我的代码:

ws.Range("C9").Formula = "=CountIf(wsRD.Range(C & Rows.count).End(xlUp).Row, ""Event"")"   'CountIf(wsRD.Range("C" & Rows.count).End(xlUp).Row, "Event") 'count(Search("Event", wsRD.Range("C" & Rows.count).End(xlUp).Row, 1))

我需要在ws.Range("C9")中插入一个公式,其中总结了wsRD.Range("C"& Rows.count ).结束(xlUp).行我可以知道代码中的问题是什么吗?感谢你的帮助.

I need to insert a formula in ws.Range("C9"), in which, it summarizes the count of the cell that have a value of "Event" in wsRD.Range("C" & Rows.count).End(xlUp).Row. May I know what's the problem in my code? Appreciate your help.

谢谢.

推荐答案

如果需要,您可以摆脱LRow变量并将其放在等式中.

You could get rid of the LRow variable and just drop it in your equation if you wanted to.

Dim LRow as Long
LRow = ws.Range("C" & ws.Rows.Count).End(xlUp).Row

ws.Range("C9").Formula = "=COUNTIF(C10:C" & LRow & ", ""Event"")"

这篇关于使用VBA在一个单元格中插入公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆