Setting cell as a named range

KarenGB

New Member
Joined
Jun 10, 2009
Messages
6
Hi

Hopefully this is a simple thing to fix.
Been looking at this all morning and can't work out what I've done.

This is the beginning of a bit of code to go through a column of data, changing each cell to be 100% and then when it's copied and pasted it to another sheet, set it to 0% and the next cell to 100%.

Excel is coming up with a debugging error on the Range(PCT).Select part. Im sure I'm missing something entirley obvious. :???:

Thanks for your help

Sub ExtractAll()
Dim PCT As Range, NextRow As Range
For x = 13 To 202
'go through population sheet
Set PCT = Range("D" & x)

Range(PCT).Select
ActiveCell.FormulaR1C1 = "100%"

'copy data
Sheets("Summary").Select
Range("2:2").Copy

'paste
Sheets("Compile").Select

NextRow = Range("A65536").End(xlUp).Row + 1
Range("A" & NextRow).Select

ActiveSheet.Paste
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Replace:
Code:
Set PCT = Range("D" & x)

Range(PCT).Select
ActiveCell.FormulaR1C1 = "100%"

With:
Code:
Cells(x,4)="100%"
 
Upvote 0
The actual error was

Code:
Range(PCT).Select
if PCT is already a range, then

Code:
PCT.Select

is the correct form

However, njimack's suggestion is by far the preferred way to achieve the result you're after, as 'select'ing cells is not usually necessary.
 
Upvote 0
Also, you could/should replace the following code:
Code:
'copy data
Sheets("Summary").Select
Range("2:2").Copy
 
'paste
Sheets("Compile").Select
 
NextRow = Range("A65536").End(xlUp).Row + 1
Range("A" & NextRow).Select
 
ActiveSheet.Paste
<!-- / message -->

with:
Code:
NextRow = Sheets("Compile").Range("A65536").End(xlUp).Row + 1
 
Sheets("Summary").Range("2:2").Copy Sheets("Compile").Range("A" & NextRow)
 
Upvote 0
Do you even need to loop? Doesn't:
Code:
Range("D13:D202").FormulaR1C1 = "100%"

do the same thing as the loop?
 
Upvote 0
I need to do 100% separately on each row for a location, copy the data that's calculated on another sheet and paste. Then go to the next location listed and repeat.
I'm having to use a government spreadsheet as a base so it's not the best.
 
Upvote 0
Well whatever works best for your situation. My point was that
Code:
Range("D13:D202").Value = "100%"

should give comparable results to:

Code:
For x = 13 to 202
     Cells(x,4)="100%"
next i

and avoiding the loop is more efficient. If the loop is part of a larger process, then it's hard to say if it's necessary without seeing your whole code.

Either way, seems your situation is fixed and ultimately that's the main thing.
 
Upvote 0
Ah, I thought that the code would have set all rows to be 100% at the same time.

Well whatever works best for your situation.
My point was that
Code:
Range("D13:D202").Value = "100%"

should give comparable results to:

Code:
For x = 13 to 202
     Cells(x,4)="100%"
next i

and avoiding the loop is more efficient. If the loop is part of a larger process, then it's hard to say if it's necessary without seeing your whole code.

Either way, seems your situation is fixed and ultimately that's the main thing.
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,550
Members
452,927
Latest member
rows and columns

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top