Any way to use vba to add vba code on a worksheet?
I need to create a worksheet with a button on it that allows people to click on the button to select the report they have and then add a double click function on their report page. And I need to share this file on the server for everyone's use.
After they run this file, they are able to double click on their report page's Range("A1:A10") and jump to sheet2 and auto-filtered by the values of the cells in Range("A1:A10").
I can do the code, just don't know how to add it on their workbook's sheet.
I have been searching for days to find the answer for writing vba by vba, but just no luck.
Related
Is it possible to use Selection to define data used in a macro button that is in another sheet.
I'm trying to make a template workbook that's first sheet is a bunch of macro buttons. I want to be able to select data in another sheet, click my button sheet, and click my button to run a macro on the data I have selected in the other sheet.
The problem that I'm running into is that sheets seem to have independent selections at the same time. So my macro always runs on the selection from the button sheet instead of the sheet I was on. Any thoughts on how I can make this work? The selection of the data needs to be dynamic, so I can't just say .Cells(1,1).value because it might not be the data I need.
Say there are two types of sheets:
a set of data-sheets
a single button-sheet which controls processing via macros tied to buttons
We code a single global range variable in a standard module. We code selection change event macros in all the data-sheets. Then:
We click on a data-sheet
We select cells on the data-sheet
the event macro on that data-sheet records the selection in the global variable
We click to get on the button-sheet
We click on a button
the button macro retrieves the global range
the button macro determines the sheet associated with the stored range (from the Parent Property) and also the cells on that sheet which we selected
the button macro processes the data
EDIT#1:
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Also just Google: Excel VBA Event Macro
(there are many examples in this forum, for example)
https://msdn.microsoft.com/en-us/VBA/Excel-VBA/articles/workbook-sheetselectionchange-event-excel
In this link is where I need to start. Every time that I change my selection it runs an event where I could maybe grab the cell values and store them in an array that will stay static when I change sheets. If I get it right I'll post it here. 5/31/2018
To Accomplish this I made rng a public variable and stored my selection from sheet2 in it. Then I used a click event in my buttons to to call the macros that I wanted to run on my range. Here are some screenshots of the codes in my modules and in my sheets. This answer is for anyone that finds this in the future.
https://imgur.com/a/DJDaQiM
The Biggest thing to take away from this is that Public Variables in vba only have to be declared once in any of your modules. NOT IN YOUR SHEET CODE. This was the biggest thing that held me back from getting this done. Good luck and contact me with any questions.
I am working on an excel spreadsheet. I have a dropdown with values. I need to add a value in there.
There is no macro and there is no connection. The only thing I found was:
I selected the cell at hand
Data -> DataValidation
In the source i can see this string =Variables!$D$1:$D$23
I do not have a sheet called variables or anything close to the word variables in any of the sheets. Where can this be coming from?
There is also protection on the workbook but not the individual sheets. Could this be the issue?
Thank you
You can usually check the contents of a hidden sheet quite easy using the Immediate Window.
So open the VBA editor (Alt-F11), go to the Immediate window (Ctrl-G), and try:
?Variables.[D17]
If this works, you can repeat this to see the other 22 validation values (or write a small sub, using Debug.Print ubstead of ?).
I'm trying to figure out if it's possible to create a formula that creates a new purchase order number every time I open up my purchase order form on excel. The current cell the number goes into is E5.
My hope is that by doing this it will eliminate duplicate numbers. They would start at 0100 starting in January.
I've searched the web for an answer but haven't found one.
Can anyone here help me?
Thanks!!!
So Using VBA, You can easily update the value of a cell when ever the excel sheet is opened.
Given your order number in row E5 this is the code you would add to the workbook
Private Sub Workbook_Open()
Cells(5, 5).Value = Cells(5, 5).Value + 1
End Sub
This piece will always update your cell value and add 1 to it whenever you open your excel sheet.
There are a couple of steps that you need to follow to get the code in your excel. Depending on your version of excel, first you will have to enable developer mode on your excel workbook you can do that by following instructions here.
Click the Microsoft Office Button Office button image, and then click Excel Options. Click Popular, and then select the Show Developer tab in the Ribbon check box.
Once you have developer mode enabled, you should be able to see a developer tab in the ribbons, click on the developer tab and then in the developer ribbon, you should be able to see the editor option, click on editor.
once you have clicked on editor, you would see a list of options in a small window, double click on "This Workbook" there. An editor window will open, and you need to copy and paste the code I have mentioned above there.
Finally save the excel sheet as xlsm (Macro Enabled sheet). And you should be all set.
This is a good theory discussion. I have a VBA heavy workbook that pulls information from a database for a specific item. Let's pretend that that item is a sales invoice. The way the workbook works now is that there is a cell in which you put a invoice number then click a refresh button and all the information for that invoice is pulled and munged in the workbook.
Is there a way that, from a command line sorta thing, set the cell with the invoice number to a value then execute the refresh when the workbook is opened? I know that I can fire the refresh macro when the workbook open via VBA, the real question is can I set a cell value to something from outside Excel. The goal is to provide a hyperlink I build that when a user clicks it, the cell value is set then the data refreshed. I am not sure where to look for this answer.
Thank you.
From reading the link I have included below, it would appeear that you cannot pass command line parameters to excel directly, however, you can use vb script which accepts parameters and then the vb script opens excel and inserts the parameter value
Link to post on MSD
Alright I know this isn't 100% related to programming (the Excel book in question doesn't use VBA at all) but I'm hoping someone can help me out with this or point me in the right direction.
My boss got a spreadsheet from a vendor that has a combobox/dropdown list with various part numbers; when you select one it populates the rest of the form with a lookup containing additional items. I've been tasked with "cracking" this and finding the list that they're using to populate so we can make use of it.
The thing is... there's no VBA code, no macros, no data connections, and only one Worksheet displayed in Excel while the lookup code references a Sheet1. I've tried to display hidden worksheets and it says there are none... so where on earth could this list be kept? My boss is getting impatient and is asking me if I've broken it yet. It's not a big deal if it can't be done, I just have no clue where to continue looking for it and I don't know what to tell my boss when he asks me if I'm done.
Can anyone help?
It's possible to hide a worksheet using VBA so that it can't be unhidden from the UI.
Try the method for un-hiding all hidden workhseets outlined here:
http://www.automateexcel.com/2004/12/14/excel_vba_unhide_all_worksheets/
My guess is that it is a Data Validation list which references a constant list of values or a range on a "Very Hidden" sheet. In Excel 2007, select one of the cells with the drop-down, click on the "Data" tab in the Ribbon, click on "Data Validation" in the Ribbon and see what you have. In Excel 2003 it is the Data -> Validation... command.
Another possibility if you know the name of the worksheet is "Sheet1" is to add a new worksheet, enter "=Sheet1!A1" into cell A1 of the new worksheet, and copy this cell down and to the right for as large of an area as you need to see the data you are interested in.
If you can post a URL to download the workbook (assuming it is not a trade secret) you would be more likely to get an accurate answer.
Could it be some data stored on the same sheet.
Possibly in columns which are either hidden, or which are far off the actual page?
Isn't this just data from the worksheet only?
Column header dropdown lists acts as filters, they show distinct values of a column.
This is a feature of Excel.
The items could be cached from a currently unavailable resource. Try saving it out to xml and searching for a known string.
Click on the cell that display a drop down list when selected
From the menubar select data>validation
In the dialog box copy the content of the source text box
Now paste the content on any empty cell on your worksheet
Select a drag it down to see the values populating the list
Chris
------
Convert your Excel spreadsheet into an online calculator.
http://www.spreadsheetconverter.com
I am assuming that you have broken this by now, but just in case you havent. This is certainly a case of data validation using a named range which is house on another sheet that was designated "very Hidden" from the vba console. You will need to open up the VBA project of this worksheet and designated the "very Hidden" sheet to just Hidden and then you will be able to unhide it, or the other setting at which point it will be viewable.