Hi guys,
I am rather new to all of this and would appreciate some help.
I am trying to create a dynamic range, but just cant get it right:
I want to get the autofill feature for C column stop once it has reached the same number of row entries in column A.
********************************************************
**********************************************************Code:Sub TestDynamicRange() ' ' TestDynamicRange Macro ' TestDynamicRange ' ' Range("A1:B6").Select Selection.Copy Sheets("Sheet2").Select ActiveSheet.Paste Range("C1").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 = "Date" Range("C2").Select ActiveCell.FormulaR1C1 = "=TODAY()" Range("C2").Select Selection.AutoFill Destination:=Range("C2:C6"), Type:=xlFillDefault Range("C2:C6").Select End Sub
Can anyone help me please?
Thanks,
Matt
Last edited by royUK; 10-26-2009 at 09:07 AM.
Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
I will add them this time only, be sure to read the Rules.
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
Check out the free Excel Toolbar
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Code Tags: Make your code easier for us to read
Why not add the Dynamic range manually?
Do you want =TODAY() or a fixed date?
Last edited by royUK; 10-26-2009 at 09:11 AM.
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel consulting, free examples and tutorials visit Excel Consulting-Excel VBA
Check out the free Excel Toolbar
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Code Tags: Make your code easier for us to read
Maybe something like this:
Putting in =TODAY() into those cells will result in a date that will keep changing. If you want the date to stay the same the next time you open the sheet, change that last line of code to:Code:Sub TestDynamicRange() Dim LR As Long Range("A1:B6").Copy Sheets("Sheet2").Select ActiveSheet.Paste Range("C1") = "Date" LR = Range("A" & Rows.Count).End(xlUp).Row Range("C2:C" & LR).Formula = "=TODAY()" End Sub
Code:Range("C2:C" & LR)= Date
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
Hi Matt,
One way would be to create a variable to record the number of rows in column A. Assuming the column A values start in row 2 use something like
Then substituteCode:Dim iARows as Integer iARows = Range("A2:A" & Range("A" & Application.Rows.Count).End(xlup).Row))
Incidentally, you don't need all the .Selects. It:s more effcient just to address the ranges in question. e.g.Code:Range("C2:C" & iArows) for Range("C2:C6")
Untested since I only have access to Excel for Mac 2008 at the moment and in their infinite wisdom Microsoft are no longer supporting VBA with Excel!Code:Dim iARows as Integer iARows = Range("A2:A" & Range("A" & Application.Rows.Count).End(xlup).Row)) Range("A1:B6").Copy Sheets("Sheet2").Range("C1").PasteSpecial(xlPasteAll) Application.CutCopyMode = False Sheets("Sheet2").Range("C1") = "Date" Sheets("Sheet2").Range("C2:C" & iArows) = "=TODAY()"
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
That worked a treat. Thanks guys!
Matt
If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].
(Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks