VBA code to Script

New Contributor

Hi guys,

I am new with Scripts, any help is appreciated.
I have a VBA code that works in an excel file but not in a shared file. So I am trying to convert the functions of the VBA code to a script but it keeps showing error.
This is the VBA code:

 

Sub Add_days()

Dim Lr As Long, Ws As Worksheet

Set Ws1 = Worksheets("Fre")

Set Ws2 = Worksheets("P")

Set Ws3 = Worksheets("D")

 

Lr1 = Ws1.Range("EGT" & Rows.Count).End(xlUp).Row

Ws1.Range("EGT2:EKK" & Lr1).Copy Ws1.Cells(2, Ws1.Columns.Count).End(xlToLeft).Offset(0, 1)

 

Lr2 = Ws2.Range("JGA" & Rows.Count).End(xlUp).Row

Ws2.Range("JGA2:JJR" & Lr2).Copy Ws2.Cells(2, Ws2.Columns.Count).End(xlToLeft).Offset(0, 1)

 

Lr3 = Ws3.Range("FGO" & Rows.Count).End(xlUp).Row

Ws3.Range("FGO2:FKF" & Lr3).Copy Ws3.Cells(2, Ws3.Columns.Count).End(xlToLeft).Offset(0, 1)

End Sub

 

I tried this in Script but it's throwing me an error (marking with bold where the error is):

function main(workbook: ExcelScript.Workbook) {
  let WS3 = workbook.getWorksheet("Drive Unit Hourly")
  let Lr3 = WS3.getRange("FGO"& Rows.Count).End(xlUp).Rows;
  // Paste to range KAG:KDX on selectedSheet from range JMK:JQB on selectedSheet
  WS3.getRange("FGO2:FKF"& Lr3).copyFrom(WS3.getRange(2,WS3.Columns.Count).End(xlToLeft).Offset(0,1), ExcelScript.RangeCopyType.all, falsefalse);
}

 

0 Replies