Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default What am i doing wrong here?

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default What am i doing wrong here?

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default What am i doing wrong here?

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default What am i doing wrong here?

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
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default What am i doing wrong here?

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

"Emma Hope" wrote in message
...
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




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default What am i doing wrong here?

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
What am I doing wrong? Ayo Excel Programming 2 January 10th 08 11:46 PM
Insert Calculated Field (wrong Qty*Price = wrong Amount) Edmund Excel Discussion (Misc queries) 8 October 4th 07 12:13 PM
where does it go wrong? minostrada Excel Programming 4 November 29th 05 07:40 AM
Is this wrong? Ctech[_23_] Excel Programming 4 October 13th 05 11:42 AM
What is wrong?? willroy[_2_] Excel Programming 1 December 12th 03 01:33 PM


All times are GMT +1. The time now is 04:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"