ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Unknown Range in Macro (https://www.excelbanter.com/excel-discussion-misc-queries/219254-unknown-range-macro.html)

scone57

Unknown Range in Macro
 
Having trouble changing a fixed range to a variable range in VBA.
When creating the macro, I used a fixed range, but now need to change this
to a variable, for future spreadsheets.

Range("R4").Select
Selection.AutoFill Destination:=Range("R4:R886")
Range("R4:R886").Select

Can anyone help?

Don Guillett

Unknown Range in Macro
 
Tell us more. Do you want to set the range or just the last row of this
range.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"scone57" wrote in message
...
Having trouble changing a fixed range to a variable range in VBA.
When creating the macro, I used a fixed range, but now need to change this
to a variable, for future spreadsheets.

Range("R4").Select
Selection.AutoFill Destination:=Range("R4:R886")
Range("R4:R886").Select

Can anyone help?



scone57

Unknown Range in Macro
 
I am not sure of the range as it will change monthly, so cant set it,but at
the moment the column states FALSE, when there is no data in the previous
columns.

"Don Guillett" wrote:

Tell us more. Do you want to set the range or just the last row of this
range.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"scone57" wrote in message
...
Having trouble changing a fixed range to a variable range in VBA.
When creating the macro, I used a fixed range, but now need to change this
to a variable, for future spreadsheets.

Range("R4").Select
Selection.AutoFill Destination:=Range("R4:R886")
Range("R4:R886").Select

Can anyone help?




Luke M

Unknown Range in Macro
 
What controls your variable? (what logic?) Assuming you already have that
part figured out, and you want to fill to row xCount (xCount being your
variable) you could change your script to

Range("R4").Select
Selection.AutoFill Destination:=Range("R4:R" & xCount)
Range("R4:R" & xCount).Select

Other ideas for your variable, depending on the logic you want, would be to
count cells and set this value equal to xCount, or have xCount equal the
value of some cell in the spreadsheet. (ie, xCount = Range("a1").value )

--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"scone57" wrote:

Having trouble changing a fixed range to a variable range in VBA.
When creating the macro, I used a fixed range, but now need to change this
to a variable, for future spreadsheets.

Range("R4").Select
Selection.AutoFill Destination:=Range("R4:R886")
Range("R4:R886").Select

Can anyone help?


Stefi

Unknown Range in Macro
 
First you should tell us how do you want to determine the range limits. E.G
if you can determine the last used row as the end of the range then

lastrow = Range("A" & Rows.Count).End(xlUp).Row

Selection.AutoFill Destination:=Range("R4:R" & lastrow)


Regards,
Stefi

€žscone57€ť ezt Ă*rta:

Having trouble changing a fixed range to a variable range in VBA.
When creating the macro, I used a fixed range, but now need to change this
to a variable, for future spreadsheets.

Range("R4").Select
Selection.AutoFill Destination:=Range("R4:R886")
Range("R4:R886").Select

Can anyone help?


FSt1

Unknown Range in Macro
 
hi
key would be to find the last row in your range and assign it to a variable.
maybe....
Dim lr As Long
lr = Cells(Rows.Count, "R").End(xlUp).Row

then plug in....
Range("R4").AutoFill Destination:=Range("R4:R" & lr)
Range("R4:R" & lr).Select

regards
FSt1

"scone57" wrote:

Having trouble changing a fixed range to a variable range in VBA.
When creating the macro, I used a fixed range, but now need to change this
to a variable, for future spreadsheets.

Range("R4").Select
Selection.AutoFill Destination:=Range("R4:R886")
Range("R4:R886").Select

Can anyone help?


Luke M

Unknown Range in Macro
 
More info please! If a column is stating FALSE, do you want to select the
column? Or the column before/after? Which rows?
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"scone57" wrote:

I am not sure of the range as it will change monthly, so cant set it,but at
the moment the column states FALSE, when there is no data in the previous
columns.

"Don Guillett" wrote:

Tell us more. Do you want to set the range or just the last row of this
range.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"scone57" wrote in message
...
Having trouble changing a fixed range to a variable range in VBA.
When creating the macro, I used a fixed range, but now need to change this
to a variable, for future spreadsheets.

Range("R4").Select
Selection.AutoFill Destination:=Range("R4:R886")
Range("R4:R886").Select

Can anyone help?




Don Guillett

Unknown Range in Macro
 

So, how can we help. You really need to help us to help you.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"scone57" wrote in message
...
I am not sure of the range as it will change monthly, so cant set it,but at
the moment the column states FALSE, when there is no data in the previous
columns.

"Don Guillett" wrote:

Tell us more. Do you want to set the range or just the last row of this
range.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"scone57" wrote in message
...
Having trouble changing a fixed range to a variable range in VBA.
When creating the macro, I used a fixed range, but now need to change
this
to a variable, for future spreadsheets.

Range("R4").Select
Selection.AutoFill Destination:=Range("R4:R886")
Range("R4:R886").Select

Can anyone help?






All times are GMT +1. The time now is 07:12 PM.

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