Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autofill - till data found 1

Status
Not open for further replies.

rampure

Technical User
May 16, 2007
17
US
Hi,

I am using a couple of macros to automate in my spreadsheet. I need to copy the formula and fill the entire column till data is found. Right now, the macro is filling, but it is going beyond the data rows and filling in for the empty rows too.

Can someone help me please.

Thanks and appreciate your response.
\
Smitha
 
What is your actual code and where are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Right now I am using this code.

Sheets("GM TYLY").Select
Columns("D:D").Select
Selection.Insert Shift:=xlToRight
Range("D5").Select
ActiveCell.FormulaR1C1 = _
"=IF(OR(RC[1]=0,RC[6]=0,RC[11]=0,RC[21]=0,RC[26]=0,RC[31]=0),""X"","""")"
Range("D5").Select
Selection.AutoFill Destination:=Range("D5:D1000")
Range("D5:D1000").Select
Calculate


But this is filling for the empty cells too. The rows for the file that I work varies, hence I have to fill a range instead of autofill.

Thanks,
Smitha
 
what about this ?
Code:
With Sheets("GM TYLY")
    .Columns("D:D").Insert Shift:=xlToRight
    .Range("D5").FormulaR1C1 = _
        "=IF(OR(RC[1]=0,RC[6]=0,RC[11]=0,RC[21]=0,RC[26]=0,RC[31]=0),""X"","""")"
    .Range("D5").AutoFill Destination:=Intersect(.Range("D5:D1000"), .UsedRange)
End With
Calculate

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PH,

Thanks so much for your response.
When I tried to use it, it gave me and "Object Required" error.

I am so sorry for asking the basic questions but I am just a beginner. Should I be using just .UsedRange or something else to it?

Thanks again.
Smitha
 
Which line of code is highlighted when the error raises ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
.Range("D5").AutoFill Destination:=Intersect(.Range("D5:D1000"), .UsedRange)

The macro stops at this line.

THanks
Smitha

 
Sorry, but the code I've posted works for me (XL2003)
 
It gives me a run time error 424 and stops.

When I tried to run the macro, it made me to remove . next to Range and UsedRange.

Anyways, appreciate your response.

Thanks,
Smitha
 
Sheets("GM TYLY").Select
Columns("D:D").Insert Shift:=xlToRight
Range("D5").FormulaR1C1 = _
"=IF(OR(RC[1]=0,RC[6]=0,RC[11]=0,RC[21]=0,RC[26]=0,RC[31]=0),""X"","""")"
Range("D5").AutoFill Destination:=Intersect(Range("D5:D1000"), UsedRange)
Calculate

Thanks for your patience PH.
Smitha
 
Why didn't you use the (tested) code I gave you 17 May 07 8:09 ?
 
I did use that code. But it still would fill in the cells with empty rows.
Since I am checking for cells with empty rows, the X tend to fill in the D column.
I want the autofill to stop when the empty row begins.

Hope I am clear.

Thanks again,
Smitha
 
You prefer something like this ?
Code:
With Sheets("GM TYLY")
    .Columns("D:D").Insert Shift:=xlToRight
    .[D5].FormulaR1C1 = _
        "=IF(OR(RC[1]=0,RC[6]=0,RC[11]=0,RC[21]=0,RC[26]=0,RC[31]=0),""X"","""")"
    .[D5].AutoFill Destination:=.Range("D5:D" & .[A5].End(xlDown).Row)
End With

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you so much PH. It works great. :)

Smitha
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top