vba auto fill issue

kelvin_9

Active Member
Joined
Mar 6, 2015
Messages
460
Office Version
  1. 2019
Hello All,

i have some data at sheet1 that i use code to divert in different columns at sheet3 and auto fill down to last row if any
however this will come with an error #1004 on below columns IF i have only 1 row data
what should i do to avoid any of this case?

VBA Code:
    Sheets("Sheet3").Select
    Range("B2").Select
    ActiveCell.FormulaR1C1 = "=RC[-1]+2"
    Selection.AutoFill Destination:=Range("B2:B" & Range("F" & Rows.Count).End(xlUp).Row)
    Range("D2").Select
    ActiveCell.FormulaR1C1 = "987654"
    Selection.AutoFill Destination:=Range("D2:D" & Range("F" & Rows.Count).End(xlUp).Row)
    Range("E2").Select
    ActiveCell.FormulaR1C1 = "Japan"
    Selection.AutoFill Destination:=Range("E2:E" & Range("F" & Rows.Count).End(xlUp).Row)
    Range("G2").Select
    ActiveCell.FormulaR1C1 = "=CONCATENATE(Sheet2!RC[12],"" "",Sheet2!RC[11])"
    Selection.AutoFill Destination:=Range("G2:G" & Range("F" & Rows.Count).End(xlUp).Row)

thank you very much for your help
 
I don't quite understand what you are trying to do with this part here:
VBA Code:
    'fill date
    Lr = WS_3.Range("A" & Rows.Count).End(xlUp).Row
    WS_3.Range("A" & Lr, WS_3.Range("B" & Rows.Count).End(xlUp).Offset(, -1)).FillDown

Firstly, we already calculated "Lr" earlier using column F. Can we still use this last row value, or does it need to be re-calculated again?
Since we seem to be trying to fill column A, that would seem to suggest that column A is blank, so I don't understand how we can then use column A to find the last row to fill down to.
What column should we look at to determine exactly how far down we need to fill column A?
base on column F to fill down column A
like your initial answer, base on column F to fill down column B, D, E, or G
However, i think there is only 1 row data copy from sheet 2, so column A can not fill down and get A2 filled as A1

thank you very much
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
sample here:

Book31
AB
1Ship out dateConsignee's_Request Date
2Ship out date#VALUE!
3
4
limited home
 
Upvote 0
If you are entering the date manually in cell A2, then get rid of the new "lr" calculation, and then use this formula:
VBA Code:
If lr > 2 Then
    WS_3.Range("A3:A" & lr).Value = WS_3.Range("A2").Value
End If
 
Upvote 0
If you are entering the date manually in cell A2, then get rid of the new "lr" calculation, and then use this formula:
VBA Code:
If lr > 2 Then
    WS_3.Range("A3:A" & lr).Value = WS_3.Range("A2").Value
End If
Joe4
thank you very much for your reply

first, this is just prefect and do what i want exactly
second, i am deeply sorry being messes, complicated and my poor presentation of my bad english

thank you
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top