Script to perform like a search macro in a spreadsheet? - excel

I use a macro in an Excel spreadsheet that allows me to type in one or multiple words and search the spreadsheet for those words. Each row of the spreadsheet that contains those words is copied over to sheet 2 of the spreadsheet. (The spreadsheet is basically a large list of inventory at my work place. So, for example, if I wanted to search our inventory for all 'red widgets', I can type the word red, and the word widget into the search field and on sheet 2 of the spreadsheet, a list of all of our red widgets would appear (even those listed as "widget red")). Could a script in Google sheets do the same thing? I would really like to use Google sheets instead of Excel for this.

A Google Apps Script can definitely do this. You would likely be best off starting from scratch rather than working from your Excel Macro code.
There are a few options for how you could set this up, but off the top of my head I would approach it like this:
Add a custom menu to the sheet, with "find & copy" menu entry
Pop up a a simple dialog using HtmlService, where the user enters the
search term.
On submission, retrieve all rows from Sheet1
Loop over the rows and search for your term in one or more columns
copy matching rows to a new array
write the array of matches to a new sheet.
See the extending sheets overview here:
https://developers.google.com/apps-script/guides/sheets
html service here:
https://developers.google.com/apps-script/guides/html/
and function references for these services here:
https://developers.google.com/apps-script/reference/spreadsheet/
https://developers.google.com/apps-script/reference/html/

Related

How to match two cells of data on different sheets and then pull a specific cell back to another sheet

I've created a multi-sheet workbook that has Manifest Data (Sheet1), Sammy (Sheet2), Trev (sheet3), Scan Data In (Sheet4). On each of the worksheets is a column labeled Connote and the data within cells of the column relates to a barcode on the paperwork we use. When I open a drivers worksheet i will scan the barcode from the paperwork and information will be pulled from the Manifest Sheet as well Time/Date Stamping using VBA. But what I'm trying to do is pull the drivers name which is in a cell on their worksheet back to the Manifest Data sheet which relates to the connote they have just scanned. I'm happy to upload the working sheet if required. Manifest Data Sheet Drivers Sheet https://1drv.ms/x/s!AiXQNwMzQ3OrnCxn4D54gpnBH9V0?e=fxsTnz
QUICK & DIRECT but limited (update)
Include following function in Manifest under the driver column (assuming driver names are Sammy, Jose, Ian, Tame, etc.):
=IF(NOT(ISERROR(MATCH(A2,Sammy!A:A,0))),"Sammy", IF(NOT(ISERROR(MATCH(A2,Jose!A:A,0))),"Jose", IF(NOT(ISERROR(MATCH(A2,Ian!A:A,0))),"Ian", IF(NOT(ISERROR(MATCH(A2,Trev!A:A,0))),"Trev", IF(NOT(ISERROR(MATCH(A2,Iwi!A:A,0))),"Iwi","no match as yet")))))
Voila!
If there's a match, it will show, else it will show "not match as yet" (you should be able to customize this message fairly easily, even as novice! :)
But if you get stuck with anything else, let me know. Will sort pronto. Just trying to make new joiners feel as welcome as possible Mr Stackoverflow editor! :)
Limitation:
There is a limitation on the number of nested 'if' statements you can have, but this is far quicker than creating additional lookups per tab, then creating a single list based upon FilterXML, then doing a lookup to that list (per below). However, if you anticipate having scores of drivers (as in plenty of them), then below would work out better than above.
There are 2 further options I can advise upon:
Harness VB - given your code / workbooks are already 'VB' 'friendly' (as you've mentioned)
Maintain a central table that contains all of the drivers, and even the associated Manifest data if you really want.
FILTERXML (harder/longer to implement/build, but robust and durable)
Create an additional column in each of your driver sheets (say, in column K for argument sake), that contains the driver name & "-" & Barcode (where barcode exists). E.g.:
=IF(A5="","",$C$2&"-"&A5)
where A5 = Barcode, $C$2 = Driver name
Insert extra sheet and create a FilterXML to combine all of these columns into a single list (in this example, I only take first 42 rows for each of the driver-name sheet (ignore funky strikethrough - this is stackoverflow's doing not mine - screenshot attests):
=FILTERXML(
""&TEXTJOIN("",TRUE,Sammy!$K$5:$K$42)&
""&TEXTJOIN("",TRUE,Jose!$K$5:$K$42)&
""&TEXTJOIN("",TRUE,Ian!$K$5:$K$42)&
""&TEXTJOIN("",TRUE,Tame!$K$5:$K$42)&
""&TEXTJOIN("",TRUE,Trev!$K$5:$K$42)&
""&TEXTJOIN("",TRUE,Iwi!$K$4:$K$42)&
"","//s[not(preceding::*=.)]")
Finally, in your Manifest sheet, you can do a lookup from the Connote (Barcode, right?) to the single Filter-XML sheet/list. A bit of cleaning with mid function to extract just the name and not the 'Barcode-Name' lookup value from step 1 gives something like this in the Driver field of the Manifest sheet:
=IFERROR(MID(INDEX(FilterXML!B2#,MATCH(""&A35&"",FilterXML!B2#,0)),1,SEARCH("-",INDEX(FilterXML!B2#,MATCH(""&A35&"",FilterXML!B2#,0)))-1),"")

Limit with creating a drop-down list dependent on a selection in excel

I have an excel file with two sheets. The second sheet (Report) contains data validation cells based on the first sheet (Data). From the second sheet, the drop-down list that displays in the Select XXX depends on the selection in the Generate Report. When the Generate Report is set to anything beyond the first five in its list, the "Select XXX" displays year as a default list (no problem with this) via the code ...INDIRECT("Year").... The problem is that excel does not allow for addition of more code (seems I hit the limit). The question is - how can I manipulate this code to accommodate every option in the Generate Report? or perhaps, is there another method to implement?
The data validation source code for the drop-down list is =IF($B$4=Data!$Q$5,INDIRECT("Client"), IF($B$4=Data!$Q$6,INDIRECT("Month"), IF($B$4=Data!$Q$7,INDIRECT("Product_Service"), IF($B$4=Data!$Q$8,INDIRECT("Sector"), IF($B$4=Data!$Q$9,INDIRECT("Trans_Type"),INDIRECT("Year"))))))
Please, see the sample file at https://drive.google.com/file/d/1VKkGHjlJzLQqx4J9kyd_bCKG4r0Q7HkG/view?usp=sharing
What you could do is put the range names in column R, and VLOOKUP them:
=IFERROR(INDIRECT(VLOOKUP($B$4,Data!$Q$5:$R$9,2,FALSE)),INDIRECT("Year"))
You could then have as many item lists as you wish.

Is there a way to automate checking for duplicates in a column and delete/notify as entering?

So I'm working on a google sheet project where I and a few others will be keeping track of every movie we watch and then scoring it from 1-10. Since this is a long-term project, the list of movie titles will get quite long and I'm trying to think of a way to notify the inputter if the movie title they're writing already exists further up in their column. Assuming it's an if-statement of some sort but very new to excel and google sheets.
Anyone have any ideas?
You might try to create validation rule for the range of cells. Right button click on the cell -> Data Validation...
Or see the link below for details
Google sheet value validation
Same solution might be implemented for MS Excel sheets
I have used conditional formatting for this. Lets say movie names are in column A. The below code would highlight duplicate entries.
=COUNTIF(A:A,A1)>1
The only issue is if there is a Typo in the movie name you could still end up whit duplicates. Example

Form for displaying and printing from Excel sheet

Is there a simple way to design a form for displaying (and printing on A4) data from an Excel sheet?
Lets say there are 200 rows in the Excel with 4 columns. I would like to make each row more readable by rearranging it like this on A4 paper (see attached diagram), instead of just printing in tabular form straight from Excel.
Can that be done without programming, but only field mapping from a form to Excel sheet?
Data entry not required. View and print only.
A4 printed output should look like this
I think you are out of luck with Excel unless you can write a VBA macro to rearrange the table data.
One option is to use a Reporting tool e.g. you can link/import the Excel data into Access and build a Report, which will allow you freedom to show each record as you like.
You could do a mail merge into Word, as if you're printing labels on a form. It's the same idea, just different data.
There are many examples online, no coding necessary.
Here's one from Microsoft, with plenty of links within in:
How to use the Mail Merge feature in Word to create and to print form letters that use the data from an Excel worksheet

Excel: Data Analyzing and Drop Down Options

Trying to create an excel spreadsheet which will allow me to select an option at the top of the page (a dropdown) which will be a list of names. I then want a grid below to be able to show (as an example) an individuals results over a month. This is a preference as I didn't want to have to go through multiple pages to view individual information and rather see it all in one location.
Thank you ! :)
Use a data validation linked to the range of student names on another sheet and then an INDEX, MATCH or VLOOKUP formulas to populate the table from the other sheets..

Resources