PC Review


Reply
Thread Tools Rate Thread

What am i doing wrong here?

 
 
Emma Hope
Guest
Posts: n/a
 
      30th Oct 2008
i have a named range RowCountPlusOne which holds a number i.e. i want to use
VBA to clear the cells after a certain number of rows i.e. row 34 to row 1000.

The code below just errors, can anyone else with what i am doing wrong.

Sheets("Breakdown").Select
strSelection = "$A$" & Range("RowCountPlusOne") & ":$BZ$1000"
Range(strSelection).Select
Selection.Clear
Range("A1:A2").Select

Thanks
Emma

 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      30th Oct 2008
Maybe change this:

strSelection = "$A$" & Range("RowCountPlusOne") & ":$BZ$1000"

To this
strSelection = Range("$A$" & RowCountPlusOne & ":$BZ$1000"



"Emma Hope" wrote:

> i have a named range RowCountPlusOne which holds a number i.e. i want to use
> VBA to clear the cells after a certain number of rows i.e. row 34 to row 1000.
>
> The code below just errors, can anyone else with what i am doing wrong.
>
> Sheets("Breakdown").Select
> strSelection = "$A$" & Range("RowCountPlusOne") & ":$BZ$1000"
> Range(strSelection).Select
> Selection.Clear
> Range("A1:A2").Select
>
> Thanks
> Emma
>

 
Reply With Quote
 
Emma Hope
Guest
Posts: n/a
 
      30th Oct 2008
Nope, still getting the same error message

Run time error '1004' - application-defined or object-defined error






"JLGWhiz" wrote:

> Maybe change this:
>
> strSelection = "$A$" & Range("RowCountPlusOne") & ":$BZ$1000"
>
> To this
> strSelection = Range("$A$" & RowCountPlusOne & ":$BZ$1000"
>
>
>
> "Emma Hope" wrote:
>
> > i have a named range RowCountPlusOne which holds a number i.e. i want to use
> > VBA to clear the cells after a certain number of rows i.e. row 34 to row 1000.
> >
> > The code below just errors, can anyone else with what i am doing wrong.
> >
> > Sheets("Breakdown").Select
> > strSelection = "$A$" & Range("RowCountPlusOne") & ":$BZ$1000"
> > Range(strSelection).Select
> > Selection.Clear
> > Range("A1:A2").Select
> >
> > Thanks
> > Emma
> >

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      30th Oct 2008
Is your code in a General module or behind a worksheet?

Sheets("Breakdown").Select
strSelection _
= "A" & sheets("breakdown").Range("RowCountPlusOne").Value & ":BZ1000"
sheets("breakdown").Range(strSelection).Select
Selection.Clear
Sheets("Breakdown").Range("A1:A2").Select

or to clear the range:
with sheets("breakdown")
.range("A" & .Range("RowCountPlusOne").Value & ":BZ1000").clear
end with

You don't usually need to select a worksheet or range to work with it. And you
don't need the $'s in the range address in your code.

Emma Hope wrote:
>
> i have a named range RowCountPlusOne which holds a number i.e. i want to use
> VBA to clear the cells after a certain number of rows i.e. row 34 to row 1000.
>
> The code below just errors, can anyone else with what i am doing wrong.
>
> Sheets("Breakdown").Select
> strSelection = "$A$" & Range("RowCountPlusOne") & ":$BZ$1000"
> Range(strSelection).Select
> Selection.Clear
> Range("A1:A2").Select
>
> Thanks
> Emma


--

Dave Peterson
 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      30th Oct 2008
This should work from anywhere in the workbook with NO selections necessary
or desirable

sub clearrowsinothersheet
Sheets("Breakdown").Range("$a" & Range("RowCountplusone") &
":bz1000").clearcontents
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"Emma Hope" <(E-Mail Removed)> wrote in message
news:22CBF803-725D-4F37-BA88-(E-Mail Removed)...
>i have a named range RowCountPlusOne which holds a number i.e. i want to
>use
> VBA to clear the cells after a certain number of rows i.e. row 34 to row
> 1000.
>
> The code below just errors, can anyone else with what i am doing wrong.
>
> Sheets("Breakdown").Select
> strSelection = "$A$" & Range("RowCountPlusOne") & ":$BZ$1000"
> Range(strSelection).Select
> Selection.Clear
> Range("A1:A2").Select
>
> Thanks
> Emma
>


 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      30th Oct 2008
Probably because I forgot to put the Parenth after the last cell refrence.

strSelection = Range("$A$" & RowCountPlusOne & ":$BZ$1000")

I assumed the "RowCountPlusOne" is a variable that equates to an integer
value. If not, then this still would not work. The entire Range statement
has to have a value that looks like: Range("$A$2:$BZ$1000")
or it will give you that error message. That is why RowCountPusOne has to
equal a number.


"Emma Hope" wrote:

> Nope, still getting the same error message
>
> Run time error '1004' - application-defined or object-defined error
>
>
>
>
>
>
> "JLGWhiz" wrote:
>
> > Maybe change this:
> >
> > strSelection = "$A$" & Range("RowCountPlusOne") & ":$BZ$1000"
> >
> > To this
> > strSelection = Range("$A$" & RowCountPlusOne & ":$BZ$1000"
> >
> >
> >
> > "Emma Hope" wrote:
> >
> > > i have a named range RowCountPlusOne which holds a number i.e. i want to use
> > > VBA to clear the cells after a certain number of rows i.e. row 34 to row 1000.
> > >
> > > The code below just errors, can anyone else with what i am doing wrong.
> > >
> > > Sheets("Breakdown").Select
> > > strSelection = "$A$" & Range("RowCountPlusOne") & ":$BZ$1000"
> > > Range(strSelection).Select
> > > Selection.Clear
> > > Range("A1:A2").Select
> > >
> > > Thanks
> > > Emma
> > >

 
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
What do I do wrong [Excuses pushing the wrong key combination earlier] Vsn Microsoft Excel Programming 6 8th Nov 2009 09:12 PM
Insert Calculated Field (wrong Qty*Price = wrong Amount) =?Utf-8?B?RWRtdW5k?= Microsoft Excel Misc 8 4th Oct 2007 12:13 PM
Provide wrong filter with search query, AD returning wrong err cod =?Utf-8?B?ZGFyc2hp?= Microsoft Windows 2000 Active Directory 1 11th Jun 2007 04:44 PM
Oracle Stored Procedure - Wrong Number of Parms Or Wrong DataTypes =?Utf-8?B?SmltIEhlYXZleQ==?= Microsoft ADO .NET 1 8th Aug 2004 01:37 AM
Windows 2000 reports wrong number of CPUs and wrong speed Rogarr Microsoft Windows 2000 1 8th Sep 2003 04:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:31 AM.