Autofill to Last Row but Miss Some Rows?

D

Dave

Hi Guys,

I'm trying to write in to a macro the ability to Autofill a column from a
cell (H7) to LastRow as you can see below, but miss out rows that have no
value in Column D.

E.g.

If

LastRow is 20
D7 has value? Yes. Fill Row.
D8 has value? Yes. Fill Row.
D9 has value? No. Skip Row.
D10 has value? Yes. Fill Row.........

Code:

Dim lastRow As Long
lastRow = Range("A65536").End(xlUp).row
Range("H7:H7").Select
Selection.AutoFill Destination:=Range("H2:H" & lastRow)
Can anyone help with this?

Thanks
Dave
 
J

John Bundy

let me know if this does not work for you

Dim lastRow As Long
Dim startRow as Long
Dim strData as String
startRow=2
lastRow = Range("A65536").End(xlUp).row
strData=Range(7,8)
For i=startRow to lastRow
If cells(i+5,4)<>"" then cells(i,8)=strData 'if D7 has something H2=H7
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top