Adding Rows in Excel

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Rick0825
Junior Coder
Posts: 28
Joined: Sun Mar 05, 2023 5:30 pm

Adding Rows in Excel

Post by Rick0825 » Sat Mar 18, 2023 4:57 pm

So you can see in my code that im trying to add 14 rows inside a Table. The code works but it wont add 14 it only adds 1. I read up on loops but im just not their yet :( or am I going at this all wrong. My code above this gets me to the right sheet and cell C5. Thanks in advance!

Code: Select all

//Add 14 Rows
Let>WIN_USEHANDLE=0
SetFocus>Eye Center.xlsx - Excel
Wait>1.0
Press CTRL
Wait>0.5
Press Shift
Wait>0.5
Send>+ * 14
Release CTRL

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1384
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Adding Rows in Excel

Post by Dorian (MJT support) » Sat Mar 18, 2023 6:16 pm

If you're working with Excel you should be using the native Excel Functions... I recommend sitting down with a cup of tea or coffee and reading up on every one of those commands - they will stand you in very good stead.

XLCreate to make our test file.
XLOpen to open it.
XLSetCell to enter data into the cells

This will get you started :

Code: Select all

//Create a workbook
IfNotFileExists>%script_dir%\test-add-rows.xlsx
  XLCreate>%script_dir%\test-add-rows.xlsx,1,xlbook
  XLQuit>xlbook
  MDL>Excel file created
Endif


//Add 14 rows of data

//Step 1. Open the xlsx file
XLOpen>%script_dir%\test-add-rows.xlsx,1,xlbook


//Step 2. Enter data in a loop
Let>loopcount=5
repeat>loopcount
  XLSetCell>xlbook,Sheet1,%loopcount%,3,Hello %loopcount%,res
  XLSetCell>xlbook,Sheet1,%loopcount%,4,World %loopcount%,res
  Let>loopcount=loopcount+1
Until>loopcount,19
For general loop help : How to Loop the Loop
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts