ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Excel VBA, dynamic references (https://www.excelbanter.com/excel-discussion-misc-queries/167318-excel-vba-dynamic-references.html)

[email protected]

Excel VBA, dynamic references
 
I would like the macro to copy a static range and paste it in spesific
rows depending on counter-formulas.

I have one counter in cell av1, at the time giving the result 331.

So for pasting in one cell, I change the recorded VBA-string:
Range("AV331").Select

into the following that works fine:
Range("AV" & Range("Av1").Value).Select

My problem is that I also have a counter in aw1, at the time giving
the result 333. So what I want to do is to paste in a range, not in a
single cell:
Range("AV331:AV333").Select

How do I do this? Tried:
Range("AV" & Range("Av1").Value:"AV" & Range("Av1").Value).Select

but did not work. Any ideas?

Brgds,
Harald

FSt1

Excel VBA, dynamic references
 
hi
not entirely sure what you trying to do but here is some sample code to
select a range.....

Dim r As Range
Set r = Range("A1:C1")
r.Select

regards
FSt1

" wrote:

I would like the macro to copy a static range and paste it in spesific
rows depending on counter-formulas.

I have one counter in cell av1, at the time giving the result 331.

So for pasting in one cell, I change the recorded VBA-string:
Range("AV331").Select

into the following that works fine:
Range("AV" & Range("Av1").Value).Select

My problem is that I also have a counter in aw1, at the time giving
the result 333. So what I want to do is to paste in a range, not in a
single cell:
Range("AV331:AV333").Select

How do I do this? Tried:
Range("AV" & Range("Av1").Value:"AV" & Range("Av1").Value).Select

but did not work. Any ideas?

Brgds,
Harald


[email protected]

Excel VBA, dynamic references
 
Hi,

I want the range AV331:AV333 to be dynamic, meaning the rownumbers
should be based on the result in the counter-cells AV1 and AW1.

In your example, Range("A1:C1") will always be selected as it is not
connected to a dynamic cell if I am not wrong.

Nattasiray

Excel VBA, dynamic references
 
Dear

You must change the code to:
Range("AV" & [Av1]&":AV" & [Av1]).PasteSpecial xlPasteValues

[] Is Evaluate Method

[email protected]

Excel VBA, dynamic references
 
On 26 Nov, 11:58, Nattasiray
wrote:
Dear

You must change the code to:
Range("AV" & [Av1]&":AV" & [Av1]).PasteSpecial xlPasteValues

[] Is Evaluate Method



Thanks for the reply but still gets error from VBA. What do you mean
by [] Is Evaluate Method? Do I need to put that in the string?

Brgds,
Harald

Jon Peltier

Excel VBA, dynamic references
 
Don't be trapped into using []. It is a handy shortcut, but it's more useful
to keep the full referencing of the object and its methods in the code:

Range("AV" & Range("AV1").Value & ":AV" & Range("AV1").Value).Select

although this is a one-celled reference the way it is written. Perhaps you
mean a variation like one of these:

Range("AV" & Range("AV1").Value & ":AV" & Range("AV2").Value).Select

Range("AV" & Range("AV1").Value & ":AZ" & Range("AV1").Value).Select

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


wrote in message
...
On 26 Nov, 11:58, Nattasiray
wrote:
Dear

You must change the code to:
Range("AV" & [Av1]&":AV" & [Av1]).PasteSpecial xlPasteValues

[] Is Evaluate Method



Thanks for the reply but still gets error from VBA. What do you mean
by [] Is Evaluate Method? Do I need to put that in the string?

Brgds,
Harald




[email protected]

Excel VBA, dynamic references
 
Tthat worked fine.

And yes, I misprinted it to be a one-celled reference in my original
question. It now is as follows:
Range("AV" & Range("AV1").Value & ":AV" & Range("AW1").Value).Select

Thanks!

Harald


All times are GMT +1. The time now is 05:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com