I need to insert some rows into Excel. I know it can be done via xlApp.ActiveWorkbook.ActiveSheet.Rows("10:10").Insert() But what I need to know, is if I can use variables in place of the 10's. I need to insert rows at various places throughout an excel document, and input data into those new rows. I need an entire row to ensure the data below and above remain where they are. Any help would be greatly appreciated.

Is this a Python question? Or did you accidentally post in the wrong thread?

Yes, you most definitely can use a variable.

from win32com.client import Dispatch

def OpenExcel():
    xlApp = Dispatch("Excel.Application")
    xlApp.Visible = 1
    xlApp.Workbooks.Add()
    return xlApp.ActiveSheet

xlSheet = OpenExcel()
row = 1

xlSheet.Rows(row).Insert()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.