Automation to last row in previous column

tchung5

New Member
Joined
Feb 7, 2025
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Excel and coding newbie here.

Trying to record an automation to auto fill column F, until the last row in column E e.g., select F2 formula and double click on the little green square. Column F is not always 20 long, it depends on last row in column E. Sometimes more, sometime less. Below is part of the code from the Excel Code Editor window. Any advice would be greatly appreciated! Thank you.

// Set range F2 on selectedSheet
selectedSheet.getRange("F2").setFormulaLocal("=TEXT(E2,\"mm/dd/yyyy\")");
// Auto fill range
selectedSheet.getRange("F2").autoFill("F2:F20", ExcelScript.AutoFillType.fillDefault);
 
Hi tchung5,

Welcome to MrExcel!!

Assuming selectedSheet = ActiveSheet try this:

VBA Code:
Dim lngLastRow As Long

    With ActiveSheet
        lngLastRow = .Cells(Rows.Count, "E").End(xlUp).Row
        lngLastRow = IIf(lngLastRow < 2, 2, lngLastRow) 'If the last row in Col. E is less than two, set the 'lngLastRow' variable to 2 or else leave it as is
        .Range("F2:F" & lngLastRow).Formula = "=TEXT($E$2,""mm-dd-yyyy"")"
    End With

I also don't know what "getRange" is? A custom function perhaps?

Regards,

Robert
 
Upvote 0
Is this in VBA, Office Script, Java, Google Scripts or some other language?
I am suspecting Office Script but seeking clarification
 
Last edited:
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: See link in post 5
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,226,771
Messages
6,192,919
Members
453,767
Latest member
922aloose

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