Read an Excel sheet and loop it line by line Python VBA

This is a memo for myself when reading data from Excel and scraping


Processing image * Source is easy for beginners ■ There are about 300 stores ■ Acquire or update some data for each store ↓ For that Read various information such as store number, store code, URL, login ID in Excel Loop with the read content (process line by line)


Load Excel sheet in Python

Load the excel setting sheet using openpyxl



import openpyxl    #Make openpyxl available
wb=openpyxl.load_workbook("test.xlsx")
sheet=wb["Setting"]    #シート名はSetting
C=[]
for row in sheet:
 C.append([col.value for col in row])

#Process the contents of the Excel sheet in a loop
#C starts from 0. The first line of the setting sheet is a heading, so the loop starts from 1.
for i in range(1,len(C)):
 print(C[i][0])
 print(C[i][1])

Read Excel sheet with VBA

It's a little complicated, but it's flexible. Read the contents of the setting sheet into the Variant type array, line by line Loop processing

Read the contents of the Excel setting sheet and loop processing line by line


Dim CRastRow As Long                         'Judgment by column A in the last row of the setting sheet
Dim i as Long
Dim C As Variant
'Read the last row of column A of the settings sheet
CRastRow = ThisWorkbook.Sheets("Setting").Cells(Rows.Count, 1).End(xlUp).Row  

'Since the first row is often a heading, it is assumed that A2 to the last row of column G are read.
C = ThisWorkbook.Sheets("Setting").Range("A2:G" & CRastRow)

'Loops start from 1 and process line by line
For i = 1 To UBound(C)
    Debug.Print(C(i,1))’A row
    Debug.Print(C(i,2)’B column
    
next i










Recommended Posts

Read an Excel sheet and loop it line by line Python VBA
Read the file line by line in Python
Read the file line by line in Python
Read Excel name / cell range with Python VBA
Notify error and execution completion by LINE [Python]
Read line by line from a file with Python
I made a tool in Python that right-clicks an Excel file and divides it into files for each sheet.
Read json file with Python, format it, and output json
The VIF calculated by Python and the VIF calculated by Excel are different .. ??
Scraping desired data from website by linking Python and Excel
How to read an Excel file (.xlsx) with Pandas [Python]
Read the standard output of a subprocess line by line in Python
Read big endian binary in Python and convert it to ndarray
Save pandas.DataFrame to Excel by sheet
Read and use Python files from Python
Create an Excel file with Python3
Ignore # line and read in pandas
Create and read messagepacks in Python
A python program that resizes a video and turns it into an image
Open an Excel file in Python and color the map of Japan
Read the file with python and delete the line breaks [Notes on reading the file]
Read CSV file with Python and convert it to DataFrame as it is
[Implementation example] Read the file line by line with Cython (Python) from the last line
I want to read CSV line by line while converting the field type (while displaying the progress bar) and process it.