![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
Hi guys,
Err.. This is kinda stupid, but I am stuck nontheless I want to write a formula using VBA that writes formula "=DCOUNTA(database, "Code", criteria)" So I wrote something like Range("A1").FormulaR1C1 = "=DCOUNTA(database," & ""Code"" & ", criteria)" and it wont run. Any help guys? Am getting dumber by the minute |
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
Quote:
If not, you can use: Range("A1").FormulaR1C1 = "=DCOUNTA(database, ""Code"", criteria)" If they are use: Range("A1").FormulaR1C1 = "=DCOUNTA(" & database & ",""Code""," & criteria & ")" Regards,
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
|
|
|
|
|
|
#3 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
Range("A1").Formula = "=DCOUNTA(database," & """Code""" & ", criteria)" Ivan |
|
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
You're not being stupid.
You do know what your problem is though? You're trying to put " into a string, but that's what is used in VBA to denote a string. So you're going to have to use Chr(34) to put double quotes in your formula. e.g. Chr(34) & "Mark" & Chr(34) would return "Mark" _________________ [b] Mark O'Brien [ This Message was edited by: Mark O'Brien on 2002-03-07 18:08 ] |
|
|
|
|
|
#5 |
|
Guest
Posts: n/a
|
Thanks for the replies
Tried it, but I got range = "C5:D6" ' String, and the range is fixed =DCOUNTA(database,"Code", 'B5':$F:$F) |
|
|
|
#6 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
Quote:
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
|
|
|
|
|
|
#7 |
|
Guest
Posts: n/a
|
Help guys..
My code Dim db As String, criteria As String, xx As String db = "DATABASE" & SVCode criteria = Range("B7:C8").Address xx = "=DCOUNTA(" & db & ",""Code""," & criteria & ")" MsgBox xx Range("D6").FormulaR1C1 = xx The MsgBox displays the correct formula, range D6 is blank! Anyone?? |
|
|
|
#8 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
ie change Formula.R1c1 to Range("D6").Formula = xx Ivan |
|
|
|
|
|
|
#9 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Winnipeg
Posts: 2,330
|
Quote:
criteria = Range("B7:C8").Address to criteria = Range("B7:C8").Address(False, False) Regards,
__________________
Barrie Davidson "You're only given a little spark of madness. You mustn't lose it." - Robin Williams |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|