简体   繁体   中英

How to drag a formula down (autofill) using VBA after finding the first blank cell

I need some help dragging a string ("Decliners") down a column in excel. I know how to do this if I knew what cell was my starting point, but I first have to find the first blank row in my data set.
Once I've found my first blank row, I need to drag my string down from there in column C3.
This string is being dragged down just one column. I also don't know the range of this data set, given that it is dynamic.

Essentially I just need to recreate the action of double clicking the bottom right of the cell and the word "Decliners" fill to the bottom of the data set.

Code to select the first blank cell in worksheet:

Dim Pastesheet As Worksheet
Dim Decliners As String
Decliners = "Decliners"

Set Pastesheet = Worksheets("Ent Gainers_Decliners")
Pastesheet.Range("C3").End(xlDown).Offset(1, 0).Select
'Where I need the word "Decliners" dragged down from the cell selected

电子表格图片

With Pastesheet
    .Range(.Range("C3").End(xlDown).Offset(1),.Cells(.Rows.Count,4).End(xlUp).Offset(,-1)).Value = Decliners
End With

This piece of code will set the value of the variable Decliners from the row after the last data set from Range C3 down until the last corresponding row of used data in column D for column C .

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