Skip to main content
Cadet | Tier 2
August 5, 2022
Question

I have an Excel sheet and I need to generate diagonally 1-100 number

  • August 5, 2022
  • 4 replies
  • 239 views
In Excel sheet diagonally I have to generate numbers from 1 to100.could you please help on this scenario. Example: 1st column 1st cell should be 1 2nd column 2 cell should be 2 3rd column 3 cell should be 3

    4 replies

    Navigator | Tier 3
    August 5, 2022

    Hi @Naveen Kumar​ , For this you could use this approach.

    1. Open Excel file (advanced or basic)
    2. assign number 1 to a number variable
    3. convert this number to a string using the "to number" activity
    4. place a "go to cell" activity and provide A1 as "specific cell"
    5. place a "set cell" activity and as "value to set" use the converted number variable (type string)
    6. place a loop and choose "for n times" - n = 99
      1. increment the number variable by 1
      2. convert the number to a string variable as you've done it outside the loop
      3. inside the loop place the activity "go to cell" and choose 'active cell: one cell to the right'
      4. place another "go to cell" and choose 'active cell: one cell below'
      5. place a "set cell" activity and use the 'active cell' - as 'value to set' you can set the number variable (as string)
    7. Close the excel file
    Cadet | Tier 2
    August 5, 2022
    Thanks for your valuable inputs ROBIN
    Cadet | Tier 2
    August 5, 2022
    Thanks for the quick reply Ashwin. Please suggest without vb script. I want to implement it in automation anywhere only.
    Ashwin A.K
    Navigator | Tier 3
    August 5, 2022

    Hi @Naveen Kumar​ ,

     

    You can either achieve it using the Click and Drag Excel Actions available in Automation 360, or you can use VBScript to achieve it:

     

    Set objExcel = CreateObject("Excel.Application")

    objExcel.Visible = True

    Set wb =objExcel.Workbooks.Add

    Set ws = wb.Worksheets(1)

     

    For i = 1 To 100

    ws.Cells(i,i) = i

    Next

     

    wb.SaveAs("FilePathGoesHere")

    objExcel.Quit

    Set objExcel = Nothing

     

    Kind Regards

    Ashwin A.K

     

     

    Blogs at TheCodingTheory - https://www.thecodingtheory.com