简体   繁体   中英

Excel 2013 VBA Resize not working

I am writing an Excel sheet with some buttons that run VBA. each button essentially picks a cell at the beginning of the range that it will eventually use, a length(number of cells that will be used), and a couple of other parameters entered by the user, and then sends the information to a sub, which resizes the Range that currently contains one cell to the number of cells entered in the length

When I use

Sub GetFromCTLGX(RangeToFill As Range, Name, TagName, TagLength)
RangeToFill = RangeToFill.Resize(1, TagLength)

my Range, "RangeToFill" is not changed at all.

If I use

Sub GetFromCTLGX(RangeToFill As Range, Name, TagName, TagLength)
RangeToFill.Resize(1, TagLength)

the code faults and doesn't compile.

has anyone else run into this problem? am I missing something?

This example resizes the RangeToFill to extend it by one row and one column. http://msdn.microsoft.com/en-us/library/office/ff193274%28v=office.15%29.aspx

numRows = RangeToFill.Rows.Count 
numColumns = RangeToFill.Columns.Count 
Set RangeToFill = RangeToFill.Resize(numRows + 1, numColumns + 1)

Easily adaptable to your code

I found the mistake in my code,

it should have been

Set RangeToFill= RangeToFill.Resize(1, TagLength)     

it's odd though.... it still doesn't explain to me why just

RangeToFill.Resize(1, TagLength)    

wasn't working, that's what is used in a majority of the examples I saw. I'm surprised that there wasn't an error for not having the Set keyword there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM