FillDown in VBA

ldashev

New Member
Joined
Mar 24, 2016
Messages
49
Hi,

Can someone please help...I have a macro where an input box prompts a user to input a single date...it's only a single date that needs to be copied down based on the length of an adjacent column:

myResponse = InputBox("Date EMAIL Recieved in MM-DD-YYYY Format")
Range("F2") = myResponse
Range("F2").Select
'Paste down
Dim lastRowFF As Long
lastRow = Range("G" & Rows.Count).End(xlUp).Row
Range("F2").AutoFill Destination:=Range("F2:F" & lastRow)

This doesn't work because the dates are auto filled so you get:


[TABLE="width: 500"]
<tbody>[TR]
[TD]12-31-2016 (Cell F2)[/TD]
[/TR]
[TR]
[TD]01-01-2017[/TD]
[/TR]
[TR]
[TD]01-02-2017[/TD]
[/TR]
[TR]
[TD]01-03-2017[/TD]
[/TR]
[TR]
[TD]01-04-2017[/TD]
[/TR]
</tbody>[/TABLE]

What I'm looking to do with .filldown is

[TABLE="class: outer_border, width: 500"]
<tbody>[TR]
[TD]12-31-2016 (F2)[/TD]
[/TR]
[TR]
[TD]12-31-2016[/TD]
[/TR]
[TR]
[TD]12-31-2016[/TD]
[/TR]
[TR]
[TD]12-31-2016[/TD]
[/TR]
[TR]
[TD]12-31-2016[/TD]
[/TR]
</tbody>[/TABLE]

I tried applying this, but it didn't work:


myResponse = InputBox("Date EMAIL Recieved in MM-DD-YYYY Format")
Range("F2") = myResponse
Range("F2").Select
'Paste down
Dim lastRowFF As Long
lastRow = Range("G" & Rows.Count).End(xlUp).Row
Range("F2").FillDown Destination:=Range("F2:F" & lastRow)
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi

If I understand correctly what you want is to copy, not to fill down.

Try:

Code:
Sub CopyDown()
Dim myResponse As Variant
Dim lastRow As Long

myResponse = InputBox("Date EMAIL Recieved in MM-DD-YYYY Format")
Range("F2") = myResponse

lastRow = Range("G" & Rows.Count).End(xlUp).Row

'Paste down
Range("F2").Copy Destination:=Range("F2:F" & lastRow)

End Sub
 
Upvote 0
Notice that you could also write the value directly in the range:

Code:
Sub CopyDown()
Dim myResponse As Variant
Dim lastRow As Long

myResponse = InputBox("Date EMAIL Recieved in MM-DD-YYYY Format")

lastRow = Range("G" & Rows.Count).End(xlUp).Row

Range("F2:F" & lastRow).Value = myResponse

End Sub
 
Upvote 0
Perfect! That worked! Thanks

Notice that you could also write the value directly in the range:

Code:
Sub CopyDown()
Dim myResponse As Variant
Dim lastRow As Long

myResponse = InputBox("Date EMAIL Recieved in MM-DD-YYYY Format")

lastRow = Range("G" & Rows.Count).End(xlUp).Row

Range("F2:F" & lastRow).Value = myResponse

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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