Forum Discussion
Auto Fill Error when output data are less than 1
Hi,
I have been trying to use below AutoFill code, but I am getting an error when data is less than 1. Is there a way for get away with this error:
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E" & Range("A" & Rows.Count).End(xlUp).Row)
Range(Selection, Selection.End(xlDown)).Select
Range("E2").Select
Application.CutCopyMode = False
9 Replies
- peanutCopper Contributor
Hi Sonal2309
The trouble is not with the code that you posted but in the previous line:
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC1,Sheet3,2,0)"
This line creates an error in the field D2. Then you tell Excel to fill-down the error which Excel refuses to do.
To check it yourself, while in Excel, press ALT+F11 and it will open VBA editor. Then use F8 to go line by line and watch you spreadsheet as you keep pressing F8.
I would correct your code, but I don't know how exactly your VLOOKUP works.
For start, look for VBA examples of VLOOKUP.
If you give me more details, maybe I can fix it for you.
- Sonal2309Copper Contributor
peanut Thank you but I know that the error is not in Vlookup and it is in Autofill (Please check the subject line of my query carefully). Although I used record macro to make the coding I know how to edit & so I was seeking help for it.
I have used the IF condition and resolved the error.
- PascalKTeamIron ContributorHi. Thanks for the file.
I assume you have created this macro with the macro recorder, there are a lot of steps in it which are not needed.
Since I sill don't know what you are actually trying to do, I can't help you.
Please explain what the macro is supposed to do- Sonal2309Copper Contributor
PascalKTeam Hi Pascal, There are some sensitive things for which I can't disclose the data. I gave you a better portion of coding already. What I was trying to reach was to avoid the Autofill data error when the data is less than 1.
However, I have achieved the same by using IF condition. I know there are coding made by recording the macro but what is the harm in it.
- PascalKTeamIron Contributor
Please see attached video and file. Is this what you need?
- PascalKTeamIron ContributorWhat exactly are you trying to do? Can you post the file?
- Sonal2309Copper Contributor
PascalKTeam Hi Pascal, Thank you for your response I cannot post the whole data but I can provide my coding.