jdorian1685
New Member
- Joined
- May 10, 2021
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hello,
I need to create a code that will autofill data to the last cell in a various columns (the last row will always have the same data in each cell). I have a code that works great for two or more rows of data but it breaks whenever there is only one row of data (when really I don't need to use the autofill code). How do I write something that will skip an autofill command if there is only one row OR alternatively, how do I write a code that will run the autofill but not break? I need something that will work on a few columns at a time not just one. Here's part of what I have so far. In this example, Column C enters a formula and then the autofill drags it down to the last Row in Column C. Column H is not an autofill but a value formatting for an entire column down to the last row.
Thanks in advane!
I need to create a code that will autofill data to the last cell in a various columns (the last row will always have the same data in each cell). I have a code that works great for two or more rows of data but it breaks whenever there is only one row of data (when really I don't need to use the autofill code). How do I write something that will skip an autofill command if there is only one row OR alternatively, how do I write a code that will run the autofill but not break? I need something that will work on a few columns at a time not just one. Here's part of what I have so far. In this example, Column C enters a formula and then the autofill drags it down to the last Row in Column C. Column H is not an autofill but a value formatting for an entire column down to the last row.
Thanks in advane!
VBA Code:
Range("C2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[2]>0, RC[2], """")"
lastRow = ActiveSheet.UsedRange.Rows.Count
Range("C2").Select
Selection.AutoFill Destination:=Range("C2:C" & lastRow)
Range("C2:C" & lastRow).Select
Range("H2:H" & lastRow).Value = Range("H2:H" & lastRow).Value
Range("H2:H" & lastRow).Select