Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Macro formula not working

0

I have a workbook with 2 worksheets; worksheet 1 was given a name as "Names" and worksheet 2 was given a name as "Data". 

In worksheet 1, I have a list of data which consist of column A - Name, column B - number, column C - Tpass, column D - pic,etc. I have a total of 45 rows with these data. Each row in column A has a different name. Eg: Row A1 is Jasmine, Row A2 is Wicha, Row A3 is Won and so on until row 45. I wan to, when I click on row A1, Jasmine's name, it will appeared all the details sheet 2. And if I click on Wicha, Wicha's details will be shown in sheet 2. However I do not know how to put into macro formula. Pls check if my formula is right. Pls kindly assist me. Thanks alot!

Answer
Discuss

Answers

0

Hi Gred, 

I dont think there is a need of macro for this. Please mention which version of excel you are using. 

1.In older verion Normal Pivot table is a better option , if you Double click on any name u will get filtered list related to that name in the next sheet.

2. If u use office 365 you can use xlookup function to retrieve full Raw data from the first sheet
XLOOKUP(lookupvalue,lookup_colum,result range(u can chose range A:BL),"No such person(if not found)")

First u can make a list of names using  Data Validation 

and Please type xlookup formula Where u want detail

Or u can also use filter function

Thanks 

Discuss

Discussion

Hi. But I'll need all the data and names (exactly in names tab). And actually data tab is empty. It will only be auto filled up if we click any of the names in names tab (the name will then appear in under "name" in data tab. Isn't it we should hyperlink? 
Gred Jul 14, '23 at 9:21 am
Add to Discussion
0

Gred

Suggest you try VLookup (which works in all versions of Excel) but first you need to remove the flawed VBA code which causes your file to fail.

Put this in cell C4 of the "data" sheet

=VLOOKUP($C$2, names!$A$6:$BL$45, 2, FALSE)

where the $ signs are important since they fix row and/or column of the ranges.and the FALSE makes it look for an exact match.

The 2 in bold means if the value C2 is found in the first colum of names!$A$6:$BL$45, show the value from column 2 of that row.

To get the date of birth in cell C8, paste the same formula but change the bold 2 to a 6 (since that data is in the column 6, F), so

=VLOOKUP($C$2, names!$A$6:$BL$45, 6, FALSE)

Change C2 to Wicha and their date of birth will appear (if you have cell formatted to display date). You get the idea hopefully- one formula with just one number to change.

Check in the Tutorials section to see how data validation can help (so you just pick names from a drop-down list in C2)

Revision 25 July 2023:

In the attached revised file, the flawed macros (and hyperlinks) have been removed and the file saved as a normal (non-macro) Excel file.

Cell C2 (yellow) in worksheet data now has List data validation, using this formula:

=names!$A$6:$A$45

Click in it and you can pick one of the 45 names on the names sheet. That will change the green cells C4 and C8 (which have the formula mentioned above). You need to change the formula so all data cells link correctly to the names sheet column.

The slight problem with that is the namesa re as they appear in the table. If you have a later version of Excel (2019 or 365 say), you could have a hidden sheet and put this array formula in single cell in an empty column:

=SORT(PROPER(names!$A$6:$A$45))
then point the list data validation formula to that instead. Names will be (kind of) alphabetic and not mixed all CAPS or lowercase

Hope this helps. If so, please be sure to mark this Answer as Selected.

Discuss

Discussion

Gred

My Answer above offers a simple way to get the exact data you need (without hyperlinks).

(I moved the following expalanation from the discussion under your question)   The VBA code in Module 1 gives a complie error and needs to be deleted- it doesn't have a sub name as the first line so is stranded. The very similar code SelectionChange (in a worksheet event behind sheet1) is flawed and just hides all but 1 row in the "data" sheet.. Again I suggest you remove it or comment it out
John_Ru (rep: 6152) Jul 14, '23 at 9:57 am
should i delete everything from the vba? thank you.
Gred Jul 16, '23 at 1:28 am
Gred, yes you should delete the VBA (especually the incomplete Module 1 code) but make a copy of the file in case you want to try the event procedure approach at a later date. You shouldn't need to though. 
John_Ru (rep: 6152) Jul 16, '23 at 2:16 am
Also be sure to unhide all rows in your "data" sheet so you can try the formula I mentioned. 
John_Ru (rep: 6152) Jul 16, '23 at 2:19 am
Did you succeed?
John_Ru (rep: 6152) Jul 18, '23 at 2:44 am
Perhaps you succeeded but your lack of response makes it feel like I just wasted my time (again!) 
John_Ru (rep: 6152) Jul 20, '23 at 3:01 pm
Hi John, sorry for late reply. My team they are discussing on another way to put the data details 😞 of coz if possible I would like it not to be in vba as I will need to share in sharepoint for all users to amend and use. 
let me get back to u when after our discussion. 🙏🏼🙏🏼

thanks a million! 
Gred Jul 23, '23 at 10:31 am
Hi. I wonder if I have 45 or more names how can I use data validation (droplist?) and the names are all full name. 
Gred Jul 23, '23 at 10:44 am
Gred, please see my revised answer and file. That should do what you request above.
John_Ru (rep: 6152) Jul 25, '23 at 2:50 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login