Working with a variable Range

BushyIII

New Member
Joined
May 15, 2008
Messages
25
My MACRO is used daily to copy data from several sheets resulting in a new sheet with a differing number of rows with every run. My problem is that I need to define this range of rows in order to do an AUTOFILL function.

I know I can use a cell to hold the row count using COUNTA. However, I cannot figure out how to then use the result of this in the range statement.
example using COUNTA within cell D100 produces a row count of 95

My MACRO needs to do the following:
A1 =Month(C1)
B1 =Year(C1)
Range("A1:B1").Select
Selection.AutoFill Destination:=Range("A2:B????"),

Thanks in advance
 
I appreciate all the help. I'll give both suggestions a try. The immediate challenge is understanding how they both work to ensure I integrate the code successfully.

Thanks again.
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
In the PM to me, you asked "Where is the fill down?"
Rather than using the .FillDown method,
Code:
With Range(.Cells(1,1), .Cells(.Rows.Count,1).End(xlup))
     .Offset(0,-3).Value = Month(oneSheet.Cells(1,3).Value)
     .Offset(0,-2).Value = Year(oneSheet.Cells(1,3).Value)
End With
puts the values directly into the cells
One difference between my and VoG's code is what is in the cells.
In the OP, the code put numbers in A1 and B1 and used .FillDown to put those same numbers in each row. The value in A3 =Month(C1).
My code does the same, but VoG's code does the equivilant of putting the formula =MONTH(RC3) in each row, so the value in A3 = Month(C3).
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top