0

So I have a project I'm working on where I have a large excel spreadsheet and I want to search one of the columns/cells and if the cell contains a certain word then I want to add a tag in another column but the same row.

So the cell would have a long description in it and if the description contained a keyword I'm looking for it would add a tag in another column in the same row. I would like to able to search for more than one keyword at a time.

I've messed around with openpyxl for awhile but that hasn't really panned out. I am familiar with python, C, C++, and Java so if you could help me with any of those languages I would really appreciate it. Python is preferred.

2
  • Can you provide some more details on what you've already tried? Commented Jun 22, 2017 at 18:21
  • Check out the pandas library in Python. It has some useful functions to help search through a dataframe. You can also read in excel sheets as dataframes. Commented Jun 22, 2017 at 18:22

2 Answers 2

1

Say we want to search column A for gold. This macro:

Sub FindGold()
    Dim r As Range
    For Each r In Intersect(ActiveSheet.UsedRange, Range("A:A"))
        If InStr(1, r.Value, "gold") > 0 Then r.Offset(0, 1).Value = "found it"
    Next r
End Sub

can produce:

enter image description here

Adjust the code to meet your schema.

Sign up to request clarification or add additional context in comments.

Comments

1
import numpy as np
import pandas as pd

# open excel file
discount = pd.read_excel("C:\\data\\discount.xlsx", sheet_name="ALL0822")

# search string in cell "Discount Total"
row, col = np.where(discount == "Discount Total")
print(row, col)

# get value from cell
cash = discount.iloc[row,col+2].values[0] 
print(cash)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.