Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,comp.apps.spreadsheets
external usenet poster
 
Posts: 1
Default Copying block (range of cells) based on a value of a specific cell-VBA

Hi. I am new to VBA. - as part of a custom function, I need to copy a
block of cells from one spreadsheet to another, based on the value in
the first column. For example, if cell A1 = '1', then copy A2:A10 to
new spreadsheet. What is the best way to do that?

Also, the user selects a range, which would be the input to my
function. How can I get the number of rows and columns in that range
and how can I refer to individual cells from there? For example, my
range is XY:ZH - I need to find out how many rows and columns are
there.. and also how do I get to the cell that is, for example, 5 rows
down, 2 columns right in my range? - something like X+2, Y+5 - how do
I convert that to a cell address?

Thank you very much..
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default Copying block (range of cells) based on a value of a specific cell-VBA

Branimir,

See my remarks in-line with your message.

HTH,
Bernie


"Branimir" wrote in message
om...
Hi. I am new to VBA. - as part of a custom function, I need to copy

a
block of cells from one spreadsheet to another, based on the value

in
the first column. For example, if cell A1 = '1', then copy A2:A10 to
new spreadsheet. What is the best way to do that?

It depends on your logic: if there is a way to calc using the number
in cell A1, then that would be best. For example, if you want to copy
nine times the number in cell A1, you could use

Range("A2").Resize(Range("A1").Value*9,1).Copy

That does the copy. Where do you want to paste it? To a blank
worksheet, to a specific row in a worksheet, or at the end of the
column in a worksheet? Where you want will affect the needed code.


Also, the user selects a range, which would be the input to my
function.

The range you could use is simply
Activesheet.Selection

How can I get the number of rows and columns in that range

Activesheet.Selection.Rows.Count
Activesheet.Selection.Columns.Count

and how can I refer to individual cells from there?

Activesheet.Selection.Cells(1,1)
is the upper left cell of the selection

For example, my
range is XY:ZH - I need to find out how many rows and columns are
there.. and also how do I get to the cell that is, for example, 5

rows
down, 2 columns right in my range?

Range(XY:ZH).Cells(6,3)
or
Range(XY:ZH).Cells(1,1).Offset(5,2)
refers to that cell.

- something like X+2, Y+5 - how do
I convert that to a cell address?

Range(XY:ZH).Cells(5,2).Address

Thank you very much.


You're welcome very much.

Bernie


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
Sum only specific cells based on value in adjacent cell KKD Excel Discussion (Misc queries) 4 May 28th 09 04:18 PM
Block cell if specific condition exists WildWill Excel Discussion (Misc queries) 8 March 16th 09 05:50 AM
Copying a block of cells so that it updates automatically Kiersten L Excel Worksheet Functions 2 October 7th 08 01:28 AM
display a range of editible cells based on specific in another cel Miki Excel Discussion (Misc queries) 0 October 10th 07 04:17 PM
how to color code a row of cells based on a specific cell value Parker1333 New Users to Excel 1 February 2nd 05 08:01 AM


All times are GMT +1. The time now is 09:16 AM.

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

About Us

"It's about Microsoft Excel"