PC Review


Reply
Thread Tools Rate Thread

Assigning string values to a range

 
 
Risky Dave
Guest
Posts: n/a
 
      14th Aug 2008
Hi,

As part of a larger function, I am putting a quite complex formula into a
specific cell on a sheet, but the compiler is giving me the good old
'Run-time error 1004:' which I thought indicated that i had made a typo
somewhere. Cant find it though :-(

The relevant lines are (apologies for the length of the formula!):

Dim NewRisk As Range
Dim NewRiskCounter As Integer
Dim Formula2 As String

Formula2 = "=(COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter +
3 & "," & Chr(34) & "adequate" & Chr(34) & ")+(2*COUNTIF(C" & NewRiskCounter
+ 3 & ":Q" & NewRiskCounter + 3 & "," & Chr(34) & "improvement Required" &
Chr(34) & "))+(3*COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter + 3
& "," & Chr(34) & "weak" & Chr(34) & "))/(15-COUNTBLANK(C" & NewRiskCounter +
3 & ":Q" & NewRiskCounter + 3 & ",)/3)"
Range("R" & NewRiskCounter + 3).Value = Formula2 ' This is where
the compiler is generating the error

What's really confusing me is that elsewhere I use what looks like an
identical approach and it works perfectly!

I assume that I've made a typo in the formula so if someone can point it out
for me I would very much appreciate it.

TIA

Dave



 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      14th Aug 2008
You have an extra comma and missing a bracket...

Formula2 = "=(COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter + 3 &
", ""adequate"")+(2*COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter +
3 & ", ""improvement Required""))+(3*COUNTIF(C" & NewRiskCounter + 3 & ":Q" &
NewRiskCounter + 3 & ", ""weak"" ))/(15-COUNTBLANK(C" & NewRiskCounter + 3 &
":Q" & NewRiskCounter + 3 & ")/3))"
--
HTH...

Jim Thomlinson


"Risky Dave" wrote:

> Hi,
>
> As part of a larger function, I am putting a quite complex formula into a
> specific cell on a sheet, but the compiler is giving me the good old
> 'Run-time error 1004:' which I thought indicated that i had made a typo
> somewhere. Cant find it though :-(
>
> The relevant lines are (apologies for the length of the formula!):
>
> Dim NewRisk As Range
> Dim NewRiskCounter As Integer
> Dim Formula2 As String
>
> Formula2 = "=(COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter +
> 3 & "," & Chr(34) & "adequate" & Chr(34) & ")+(2*COUNTIF(C" & NewRiskCounter
> + 3 & ":Q" & NewRiskCounter + 3 & "," & Chr(34) & "improvement Required" &
> Chr(34) & "))+(3*COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter + 3
> & "," & Chr(34) & "weak" & Chr(34) & "))/(15-COUNTBLANK(C" & NewRiskCounter +
> 3 & ":Q" & NewRiskCounter + 3 & ",)/3)"
> Range("R" & NewRiskCounter + 3).Value = Formula2 ' This is where
> the compiler is generating the error
>
> What's really confusing me is that elsewhere I use what looks like an
> identical approach and it works perfectly!
>
> I assume that I've made a typo in the formula so if someone can point it out
> for me I would very much appreciate it.
>
> TIA
>
> Dave
>
>
>

 
Reply With Quote
 
Risky Dave
Guest
Posts: n/a
 
      14th Aug 2008
dmoney,

Thanks for the response, I managed to find the errors - I hadn't paired the
brackets accurately.

FYI, although the formula does contain variables (NewRiskCounter), these
values are calculated before the string is passed to the cell defined by
Range(), which is why it works.

Dave

"dmoney" wrote:

> It seems that the formula contains variables. I think you need to do the
> calculations outside of the string expression as the cell you are populating
> cannot reference your code to determine what the variable means.
>
> HTH
>
> dmoney
>
> "Risky Dave" wrote:
>
> > Hi,
> >
> > As part of a larger function, I am putting a quite complex formula into a
> > specific cell on a sheet, but the compiler is giving me the good old
> > 'Run-time error 1004:' which I thought indicated that i had made a typo
> > somewhere. Cant find it though :-(
> >
> > The relevant lines are (apologies for the length of the formula!):
> >
> > Dim NewRisk As Range
> > Dim NewRiskCounter As Integer
> > Dim Formula2 As String
> >
> > Formula2 = "=(COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter +
> > 3 & "," & Chr(34) & "adequate" & Chr(34) & ")+(2*COUNTIF(C" & NewRiskCounter
> > + 3 & ":Q" & NewRiskCounter + 3 & "," & Chr(34) & "improvement Required" &
> > Chr(34) & "))+(3*COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter + 3
> > & "," & Chr(34) & "weak" & Chr(34) & "))/(15-COUNTBLANK(C" & NewRiskCounter +
> > 3 & ":Q" & NewRiskCounter + 3 & ",)/3)"
> > Range("R" & NewRiskCounter + 3).Value = Formula2 ' This is where
> > the compiler is generating the error
> >
> > What's really confusing me is that elsewhere I use what looks like an
> > identical approach and it works perfectly!
> >
> > I assume that I've made a typo in the formula so if someone can point it out
> > for me I would very much appreciate it.
> >
> > TIA
> >
> > Dave
> >
> >
> >

 
Reply With Quote
 
Risky Dave
Guest
Posts: n/a
 
      14th Aug 2008
Jim,

Thanks managed to find it about 5 minutes after I posted - only taken about
2 1/2 hours tryig to sort this out!

Dave

"Jim Thomlinson" wrote:

> You have an extra comma and missing a bracket...
>
> Formula2 = "=(COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter + 3 &
> ", ""adequate"")+(2*COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter +
> 3 & ", ""improvement Required""))+(3*COUNTIF(C" & NewRiskCounter + 3 & ":Q" &
> NewRiskCounter + 3 & ", ""weak"" ))/(15-COUNTBLANK(C" & NewRiskCounter + 3 &
> ":Q" & NewRiskCounter + 3 & ")/3))"
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Risky Dave" wrote:
>
> > Hi,
> >
> > As part of a larger function, I am putting a quite complex formula into a
> > specific cell on a sheet, but the compiler is giving me the good old
> > 'Run-time error 1004:' which I thought indicated that i had made a typo
> > somewhere. Cant find it though :-(
> >
> > The relevant lines are (apologies for the length of the formula!):
> >
> > Dim NewRisk As Range
> > Dim NewRiskCounter As Integer
> > Dim Formula2 As String
> >
> > Formula2 = "=(COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter +
> > 3 & "," & Chr(34) & "adequate" & Chr(34) & ")+(2*COUNTIF(C" & NewRiskCounter
> > + 3 & ":Q" & NewRiskCounter + 3 & "," & Chr(34) & "improvement Required" &
> > Chr(34) & "))+(3*COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter + 3
> > & "," & Chr(34) & "weak" & Chr(34) & "))/(15-COUNTBLANK(C" & NewRiskCounter +
> > 3 & ":Q" & NewRiskCounter + 3 & ",)/3)"
> > Range("R" & NewRiskCounter + 3).Value = Formula2 ' This is where
> > the compiler is generating the error
> >
> > What's really confusing me is that elsewhere I use what looks like an
> > identical approach and it works perfectly!
> >
> > I assume that I've made a typo in the formula so if someone can point it out
> > for me I would very much appreciate it.
> >
> > TIA
> >
> > Dave
> >
> >
> >

 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      15th Aug 2008
That's usually how it works!

Barb Reinhardt



"Risky Dave" wrote:

> Jim,
>
> Thanks managed to find it about 5 minutes after I posted - only taken about
> 2 1/2 hours tryig to sort this out!
>
> Dave
>
> "Jim Thomlinson" wrote:
>
> > You have an extra comma and missing a bracket...
> >
> > Formula2 = "=(COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter + 3 &
> > ", ""adequate"")+(2*COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter +
> > 3 & ", ""improvement Required""))+(3*COUNTIF(C" & NewRiskCounter + 3 & ":Q" &
> > NewRiskCounter + 3 & ", ""weak"" ))/(15-COUNTBLANK(C" & NewRiskCounter + 3 &
> > ":Q" & NewRiskCounter + 3 & ")/3))"
> > --
> > HTH...
> >
> > Jim Thomlinson
> >
> >
> > "Risky Dave" wrote:
> >
> > > Hi,
> > >
> > > As part of a larger function, I am putting a quite complex formula into a
> > > specific cell on a sheet, but the compiler is giving me the good old
> > > 'Run-time error 1004:' which I thought indicated that i had made a typo
> > > somewhere. Cant find it though :-(
> > >
> > > The relevant lines are (apologies for the length of the formula!):
> > >
> > > Dim NewRisk As Range
> > > Dim NewRiskCounter As Integer
> > > Dim Formula2 As String
> > >
> > > Formula2 = "=(COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter +
> > > 3 & "," & Chr(34) & "adequate" & Chr(34) & ")+(2*COUNTIF(C" & NewRiskCounter
> > > + 3 & ":Q" & NewRiskCounter + 3 & "," & Chr(34) & "improvement Required" &
> > > Chr(34) & "))+(3*COUNTIF(C" & NewRiskCounter + 3 & ":Q" & NewRiskCounter + 3
> > > & "," & Chr(34) & "weak" & Chr(34) & "))/(15-COUNTBLANK(C" & NewRiskCounter +
> > > 3 & ":Q" & NewRiskCounter + 3 & ",)/3)"
> > > Range("R" & NewRiskCounter + 3).Value = Formula2 ' This is where
> > > the compiler is generating the error
> > >
> > > What's really confusing me is that elsewhere I use what looks like an
> > > identical approach and it works perfectly!
> > >
> > > I assume that I've made a typo in the formula so if someone can point it out
> > > for me I would very much appreciate it.
> > >
> > > TIA
> > >
> > > Dave
> > >
> > >
> > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Designer auto assigning bogus string resource values Flyte Microsoft Dot NET Framework Forms 1 15th Jun 2007 11:19 PM
Problem assigning values to a range of cells =?Utf-8?B?Sm9obiBLZWl0aA==?= Microsoft Excel Programming 3 7th Oct 2005 09:00 PM
Assigning ranges for values (e.g., $1,005 the range is ">$1K to 5K =?Utf-8?B?amVubmlmZXI=?= Microsoft Excel Worksheet Functions 1 11th Aug 2005 02:09 PM
Assigning values from a selected range to individual variables =?Utf-8?B?RHIuIFNjaHdhcnR6?= Microsoft Excel Programming 5 27th Jan 2004 02:27 PM
Values differ after assigning 1 string to another Stephen Graybeal Microsoft VB .NET 0 21st Aug 2003 03:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:03 PM.