PDA

View Full Version : search, help needed



didig
11-03-2013, 04:01 AM
Hello:

I would like to write something so that I get an input msg. box, where I can insert a word to search. and I would like to search only the titles of all the charts in the workbook (my excel file). Ideally I would like to be able to have the code in 1 excel file and be able to select the file to search and have its location (cell and sheet or just sheet) returned in a cell.

I would appreciate any help to put this together.

Thanks to everyone :hi:

SamT
11-04-2013, 08:00 AM
First, do you know the difference between a Chart Object and a ChartObject Object? The keyword "Chart" is very ambiguous. You must clarify exactly what you mean

Second, to clarify what you have and what you want to accomplish:

You have many workbooks with many charts, (Chart Objects and or ChartObject Objects.)

You have a workbook you would like to (accomplish) have a search function in that will store the location of the object whose title you search for in the many Workbooks that contain charts.

astranberg
11-04-2013, 09:33 AM
Sub Test1()
findChart = InputBox("Chart Object To Find")
For Each ws In ActiveWorkbook.Worksheets
For Each cht In ws.ChartObjects
If findChart = cht.Name Then
shtName = ws.Name
chartLoc = cht.Top
End If
Next cht
Next ws
End Sub

didig
11-04-2013, 12:33 PM
thanks guys and sorry for the ambiguity.
I have a lot of charts in 1 workbook. The code above works almost perfectly but not exactly what I need to do. basically I have the chart title but I do not know where the chart is. I tried to change the code to chart title as below

If findChart = cht.title Then

but it did not work. how can I let it know that I want to search the chart title and then it either puts the cursor there or tells me the chart "location".

Thanks a lot guys you are amazing. I can upload an excel file if any easier. :clap:

astranberg
11-04-2013, 12:48 PM
You should be able to add cht.Select if that's what you want to do. It should be cht.ChartTitle, not cht.Title, but I still couldn't seem to get that to work.

didig
11-04-2013, 02:01 PM
Tnx Astranberg. They idea was gr8 but I cannot get it to work either. I tried both cht.ChartTitle and ChartTitle.Text. Nothing I get an error and it goes to debug. I have excel 2007. Maybe smthing changed...

Any way, it was much appreciated. maybe someone knows where the title of the chart gets stored. it seems that's the missing piece :-)