Activate selection of cells

  • Thread starter Thread starter Maze
  • Start date Start date
M

Maze

All:

How do I make the selection of cells "0"? It will only work for the first
cell, see code below - thank you.

Sheet2.range("c141,e141,g141,i141,k141").Select
Sheet2.range("c146,e146,g146,i146,k146").Select
ActiveCell.FormulaR1C1 = "0"
 
The ActiveCell is just that a (single) cell that is active; Selection, on
the other hand, is comprised of all the cells that are selected. It is
unclear what your code is supposed to be doing. For example, your second
line of code will, in effect, unselect the selection made by your first line
of code in order to select the indicated cells. Also, "0" is not really a
formula; it is a value. Perhaps if you told us what you think this code will
do for you, then maybe we can offer you more to work with.

Also, for your consideration, perhaps this previous posting of mine (a
response to another person using Select/Selection type constructions) will
be of some help to you in your future programming...

Whenever you see code constructed like this...

Range("A1").Select
Selection.<whatever>

you can almost always do this instead...

Range("A1").<whatever>

In your particular case, you have this...

Range("C2:C8193").Select 'select cells to export
For Each r In Selection.Rows

which, using the above concept, can be reduced to this...

For Each r In Range("C2:C8193").Rows

Notice, all I have done is replace Selection with the range you Select(ed)
in the previous statement and eliminate the process of doing any
Select(ion)s. Stated another way, the Selection produced from
Range(...).Select is a range and, of course, Range(...) is a range... and,
in fact, they are the same range, so it doesn't matter which one you use.
The added benefit of not selecting ranges first is your active cell does not
change.
 
Sheet2.range("c141,e141,g141,i141,k141").value = 0
or using a bigger range:
Sheet2.range("c141,e141,g141,i141,k141,c146,e146,g146,i146,k146").value = 0
 
Back
Top