View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc,microsoft.public.excel.programming,microsoft.public.excel
Rick Rothstein \(MVP - VB\)[_2275_] Rick Rothstein \(MVP - VB\)[_2275_] is offline
external usenet poster
 
Posts: 1
Default how to do these things in Excel with and without VBA?

The cells you wish to multiply by 2 (or do anything else with, within
reason) do not have to be in a contiguous block of cells. Select a bunch of
cells with numbers in them on a worksheet (make sure you use the Ctrl key to
select them so that you have some contiguous cells and some isolated cells
in the selection), then right-click the tab for that worksheet and select
View Code (this will take you to the VBA editor and make sure the active
code window is set for the worksheet where your selections are). Now,
execute this statement in the Immediate window...

Selection.Value = 2 * Selection.Value

Now go back to the worksheet and you will each selected cell's value is
twice as big as it was before. You, of course, do not have to use the
Selection to do this; you can specify a discontiguous range directly in code
and to the same operation...

Range("A1:C4, J4, L6:L9").Value = 2 * Range("A1:C4, J4, L6:L9").Value

And, of course, multiplication is not all you can do...

Range("A1:C4, J4, L6:L9").Value = "XX" & Range("A1:C4, J4, L6:L9").Value

where I have concatenated "XX" onto the front of whatever is in each cell in
the discontiguous range "A1:C4, J4, L6:L9".

Rick


"LunaMoon" wrote in message
...
Hi all,

I am learning Excel/VBA via using it in real day-to-day work.

Two questions:

1. How to multiple a whole range of cells by 2 all together and all at
once? (element-wise).

Of course, I am looking for more flexibility, such as apply a function
to the whole region of cells.

I understand that it could be done for rectangular shapes; is there a
way to do this by first select a bunch of cells and label the cells as
one single region(non-rectangular and non-regular shaped), and then
apply function to this region as a whole?

2. This time I have a function in XLL (treated as black box here, it
usually takes a column of values, or a row of values, treating these
cells internally as a "vector" in C++). I have verified that the
function works properly.

But now, what if I want to select cells which are scattered around and
not arranged in one row or one column ...

It's like a multiple selection, and I don't have criteria for VSelect
-- the cells should be selected by hand, no uniform criteria for any
automatic selection...

Please help me!

Thanks a lot!