Can´t find my code in excel vba - excel

I have written a code that should run when a cell in the worksheet changes. It works well and fast.
Now I want to add another case to the code... but now I can´t find it.
Can I somehow search for the code? There are no modules or forms and I have tried to select worksheet and change.. but the code does not appear.
Please help
Regards
Henrik

If the code reacts on Worksheet change, it's within Microsoft Excel Objects for the sheet

I don't know if this will help, but when my code hides (hugely frustrating!), I hit the "Macros" button - it should show up in the list there if it's working in your sheet. Then you can select it, choose "step into", and at least get to where you can edit the code. Good luck!

Related

Dynamically merge tables in Excel

I've found several sources that appear to give me a solution to my need, but each one has come up short. I think my solution is in using VBA UNION; however, I am a complete VBA noob, so I feel like I shooting in the dark. Here is my need.
I have a worksheet with multiple tabs.
Each tab has the same headers for the first 10 columns.
I'd like a sheet that is a summary of the first 10 columns of all other sheets combined.
I thought if I made each sheet a table and named each, I could create a range of ranges and then just call that combined range on the summary tab. My thought is there a solution somewhere with Union here, but I don't know enough to know if that's right or not.
I need basically what this solution is, but rather than it running on a run command and doing a copy/paste, the result just needs to dynamically update. https://danwagner.co/how-to-combine-data-from-multiple-sheets-into-a-single-sheet/
As a Google Sheets user, this is super simple, but I have to use Excel for this. I feel like there must be a simple solution that I am just completely missing. In Sheets I'd have just done ={range1;range2;range3;etc} and I'd have had my output, if that helps someone get what I need.
Any help here is very much appreciated.
Part of what is great about VBA is that it is an event-driven language, so you can set your code to run every time a cell is changed, workbook is saved, etc. instead of having to press a button. I recommend reading up to section 3.1 of Excel VBA Events - An Easy Guide where it explains how you can use:
Private Sub Worksheet_Change(ByVal Target as Range)
CombineDataFromAllSheets
End Sub

Cannot run the macro Listbox4_Change. The macro May not be available in this workbook or all macros disabled

Can anyone please help me with excel issue. I have created a dynamic dashboard in excel using sumifs on data layer and index match functions on presentation layer. I have placed a simple List box form control with no VBA or macro.
My dashboard was working fine, without any issue, but on final step I was just trying to make the List box control float on the sheet with scrolling.
I found a vba code, I opened vba from developer mode, pasted code, but that deleted same.
Since then upon any selection of List box item, it is giving me error “ Cannot run the macro Listbox4_Change. The macro May not be available in this workbook or all macros disabled.”
I have tried pretty much every thing I found on google. Created a macro and deleted, copied one line code in all sheets of vba and deleted, enabled Macro security setting, but nothing really is working .
I am stuck badly.
It sounds like you've added a macro and then removed it, but haven't removed the macro assignment on the list box.
Right-click on the control and choose Assign Macro, delete the Macro name, and hit OK.

Changing the text of an Options Button on Excel for Mac 365

I have made a workbook on Excel for Windows and I am now trying to get it to work on Excel for Mac. (I have Office 365, so I have the most current versions of Excel on both computers.) For the most part it works fine, but there are a few things that aren't working. One bit that is really confusing me is changing the text of some Option Buttons that I have on a few different sheets. (Based on some input, the text of the Option Buttons needs to change.)
In Excel for Windows, here's how I change the text:
ThisWorkbook.Sheets("Sheet1").Shapes("OptionButton1").TextFrame.Characters.Text = "New Text"
The above works whether or not Sheet1 is the ActiveSheet, and whether or not OptionButton1 is in a column that is currently hidden.
That line of code does not work on Mac. For it to work, I have to split it up, and introduce a Select command. I also have to Activate the sheet.
With ThisWorkbook.Sheets("Sheet1")
.Activate
.Shapes.Range(Array("OptionButton1")).Select
Selection.Characters.Text = "New Text"
End With
It's annoying that after the code runs, one Option Button is selected on each page.
Another annoying thing -- I have to make sure the column that the Option Button is in is not hidden. I assume this is because I am being forced to select the Option Button itself, and it can’t do that if it’s in a hidden column?
I would love to NOT have to select the Option Button at all, but I can't figure out any other code to change the text. To be honest, the only reason I was able to come up with this code is because I recorded a macro of myself actually doing it.
If anyone knows about Excel for Mac and could help, please let me know. Thanks!
I would add ActiveSheet to the code to prevent all objects named Option Button 1 from being selected at the same time
ActiveSheet.Shapes.Range(Array("Option Button 1")).Select
Hiding columns does not affect option buttons' visible property on Mac or Windows. Option buttons have their own hidden/visible property.
Using this syntax works on both Mac and Windows, so why not go with it intstead of the older way?

Excel VBA - Multiple buttons pointing to same event

I am currently working on some excel document to automate it as much as possible.
For this I have to add the same button (let's call it an Erase All button for example) in each of the sheets.
Till here is OK. I have added it and all works fine. The problem is that the onClick event code is replicated in all the different sheets as a new Microsoft Excel Object code. What I would like is all the buttons to point to a single Module so I dont have to replicate code anywhere.
I come from a .Net environment and I know that VBA may have some restrictions or different usage but wondering whether I can avoid the onClick event in every sheet and put this onClick on a single generic module.
As a workaround I added my functionality as a SUB in the module and I call it from each of the different onClick events but if it is possible to directly clean all the sheet-specific code then it would be great :)
Any clue on that?
Hope is enough clear but in case need some more description please let me know and will try to add some graph/pic
Thanks a lot in advance!!
You can assign the same macro to each of the buttons. (Just right click on the button and 'assign macro')
As long as you designate the ActiveWorksheet as the sheet to process within the macro, this should be fine.
Alternatively you could instead create a non-modal userform with the required generic buttons which then has code to work on the active worksheet when pressed

vba excel: How to fill in two cells in a row with text

I need to make a header in my excel sheet using VBA. Seems pretty simple, but when I do this
Worksheets("New_Students").Range("A1").Value = "studentID"
Worksheets("New_Students").Range("B1").Value = "ISUID"
only the first line works and not the second one. What am I forgetting?
Try this:
Inside the excel application go to the developer tab on the ribbon and click record macro.
Type the values into the two cells manually.
Click stop recording and view the macro it created.
This would show you VBA code that will work and you can compare it to what you have in order to trouble shoot.
This is called recording a macro and can be very helpful in solving problems. In fact I would suggest doing so almost every time before asking a question here.

Resources