Public And Private Sub: Move To The Next Curios Level Of Understanding Macro And VB Coding
Jun 29, 2006
Where can I obtain some working examples or explanations as to what, where, when, why, and how these Public and Private Sub are correctly implemented? I see these code used extensively but not sure why it's there yet. A macro which uses a Private Sub is in one of my workbooks. Due the "progress" of things from here I now need to move to the next curios level of understanding Macro and VB coding.
View 3 Replies
ADVERTISEMENT
Jan 1, 2008
how is the best method to link up forms to "talk" to my modules? (aka set variables inside my module script)
the way i understand it with my C++ background, it seems like separate forms and modules act much like private declarations do inside class calls.
I know that in C++ i can declare a friend class to grant access to communication between classes... and i'm wondering if such a procedure is possible in VBA as well...
or to break it down for those not familiar with C++, quite simply, is there a method of code i can implement to have different user forms and modules to talk to eachother? as it seems that any variable declaration is all inclusive to that one object.
The only way i can think of passing variables is by having my code create a worksheet, paste variables one by one into cells, bounce to the destination module, and import those declarations one by one through the cell contents, and remove the sheet after use...
I know i can do it that way, but i really dont want to as that is pretty darn sloppy, and a mickey mouse way to tie my program together.
View 3 Replies
View Related
Dec 31, 2013
I have a macro that pulls specific data from a CSV, then I copy that extract to my master excel doc (setup by year), so I can put the data into pivot tables and charts. This is used to create "management" style reports.
This data has IP addresses in it. Both internal and external. Trying to find a formula that will look at Cell A, where the IP address is and input either External or Internal into column AA, based on the number.
Internal would be numbers between 10.0.0.0 and 10.255.255.255, 172.16.0.0 and 172.31.255.255, and 192.168.0.0 and 192.168.255.255. Anything not in those three ranges would show as External.
View 6 Replies
View Related
Jan 23, 2013
I have a sheet on the left is a list of document names, next to the list is a hyperlink to the actual document. On the right is a drop down list.
The list contains:
Started
In Progress
Complete
I want each person to be able to use the dropdown list to move to the next level but not be able to go backwards.
Example of how it would work:
A person would click the link to the document and set the status to Started in the drop down.They would read half the document and set the list to In progress. However they would not be able to go back to Started or a blank cell once they have set it to In Progress. The same applies to the next level, if they set it to Complete, they cannot change it to anything. Perhaps before "locking" it as Complete there could be a message box warning that the action is not reversible and giving the option to leave it as In Progress.
View 6 Replies
View Related
Oct 18, 2007
I'm trying to move my VBA programming to the next level and use more efficient code.
I'm wondering if there is a faster way to run the loop below, perhaps removing the 'For c = 2 to LastRow' as it seems a little clunky to me.
For c = 2 to LastRow
If Cells(c, Range("Product_Type").Column) = "" Then _
Cells(c, Range("Product_Type").Column).Interior.ColorIndex = 41
Next c
I've seen a similar thing somewhere where it was all done in one statement without the loop.
View 9 Replies
View Related
Aug 14, 2012
I am trying to bring up a form after clicking the "ok" button on another form. Both forms are defined in my public sub, so basically, the module creates both forms, calls the first form, and hides the second form. Then the first form hides itself and shows the second form. However, when second form is defined using "dim", the first form can't find it to show it, and when I make the second form "public" in my public sub, I get the error that it is an invalid attribute or function.
Here is the code from my sub that applies to this error:
Code:
Public Sub PutInEngine()
Dim InputForm As New FrmInputs
InputForm.Show
[Code].....
View 3 Replies
View Related
Mar 17, 2014
I have 3 different sheets with a private sub on each all labelled
Private Sub CommandButton1_Click()
The macro's runs fine on each page.
I want to put a macro on a separate sheet that i can run each of those macro's
I did initially copy the original private macro and change the
Private Sub CommandButton1_Click()
to
sub report()
But I couldn't do all 3 in the same manner. i did change each name to something different... the other 2 subs did run, but they didn't do anything except put the massage box on the end saying that "the macro has finished".
The private macros are on sheets 26, 28 and 12.
View 3 Replies
View Related
Nov 14, 2008
I need a line of code so that when I hit commandbutton2, the Private Sub Worksheet_Change(ByVal Target As Range) event macro on the same page DOESN'T run. The button clears certain lines, and when it runs the change event it ends up in an error, and I don't need it to run when hitting the commandbutton.
View 6 Replies
View Related
Jul 12, 2007
How do disable Private Sub Macro
I have a private sub macro for Sheet1 as shown below
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address "$B$2$" Then Sheets("Start").Select
Exit Sub
End Sub
And I have another macro (call ADDNumLine) that add additional data to the Sheet1. How do I temporally disable the Private Sub above when executing Macro AddNumLine?
View 9 Replies
View Related
May 26, 2014
I have declared one variable outside of Sub. And in a Sub I gave it a value. Then I run a macro, which should take that value and print it to the cell. However, it is printing a blank cell, not even "0" (I run a macro and anything in that cell is removed).
[Code].....
and then my macro:
[Code]......
How to make so macro see my variable declared outside of this macro?
View 8 Replies
View Related
Jul 21, 2007
I am making a spreadsheet that sorts and pastes, but I need to know if I can add a code to the Sort and Paste Macro that will open the second spread sheet needed without just already having it open and using the
Windows("estimate sheet one.xls").Activate
View 2 Replies
View Related
Oct 17, 2003
When in a ThisWorkbook macro, I want to call a sub/macro in a Module. Usually you can just do a CALL MACRO1, and it will find it. But my MACRO1 is Private as I don't the users to be able to do a Tools, Macro, Macros and see it. So I don't want to make it a Public macro. So how do I call the private sub/macro from within ThisWorkbook?
Can I proceed the sub/macro's name with the name of the module, kind of like CALL MODULE1.MACRO1? Or do I have to make it public?
View 9 Replies
View Related
Mar 26, 2008
I have a sheet that has a macro on it, I would like to run that macro programaticaly but Im not able to call it using Call mymacro type of code. The code that calls the macro resides in a module and the macro is in a sheet. Obviously they are not talking, is there a way to run it remotely without moving the macro into the module?
View 9 Replies
View Related
Jul 8, 2009
I am Having trouble calling an macro that is not in the module that is calling it. I thought that all I had to do was label the Macro as Public instead of private, but it is not working. If I copy and Paste the Macro code into the module that is calling it, everything works just fine, but this is making it difficult to keep things organized.
View 8 Replies
View Related
Apr 27, 2012
I would like to have something that will auto run the code in Module1 when the Excel File is opened, but I do not want to code tansfered into the file when it is saved in its location.
I don't mind if the code is tranfered to saved file if in fact I can make sure the code is not run when the new file is opened...
Everything is working as intended at the moment, but when openeing the saved file the entire macro tried to run again. This is what I do not want...
I currently have the following code in Module1.
Private Sub Workbook_Open()
'
' Format_Copy_&_Paste
'
Application.OnKey "^+r", "Warehouse_Cost_Summary"
'
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "DataSet"
[Code] ..........
View 4 Replies
View Related
Sep 6, 2006
Although not a complete novice, I am fairly new to EXCEL/VBA.
Is there a script that can be embedded into an EXCEL workbook that checks the Macro security of the PC, and if set to HIGH, shows a message that states that "Macro security is too high to open this workbook".
With security set to high, Excel will open my w/ book, but not run any of my checks that are set in the module. So a "catch 22" really, I need the macros to run to that it is being opened on an authorised computer etc, but if security is set to HIGH, then they don't run, similarly, if I put a macro in to check the macro setting, it won't run unless the security is set to medium.
View 9 Replies
View Related
Apr 3, 2008
Is there a way of coding a macro in VBA that allows you, with one macro, to enter text in one cell and at the same time enter a value to the cell on it's right?
I don't want to name the cells, but I wondered if you could add to the code a piece of code that basically said "Select the cell to this cell's right and add the value x".
View 9 Replies
View Related
Apr 20, 2013
I have a spreadsheet with near 300 tabs, each with a picture in the tab. The main tab has a list of all other tabs, the goal is to allow the user to click on a cell next to an entry, and have Excel flash the referenced tab to allow the user to see what the entry is referencing. I have written a simple macro that activates a desired tab, unhides it, displays a message box to pause the macro, rehides the tab, then returns the user to the main tab.
Rather than creating a macro for all 300 tabs and creating buttons I would love to use the Private Sub Worksheet_SelectionChange(ByBal Target As Range) or some variation thereof, to make my life much easier. The name of the tab is in cell A2, so I would want to have the user click on cell A1, activate the macro, then take A1 to A2 with something like A1 = A(x+1)->A2, then display the tab listed in A2. So rather than have 300 macros with Sheets("XYZ").Visible = True, I would love it to read Sheets(contents of referenced cell).Visible = True. with the contents of referenced cell coming from some manipulation of the cell I clicked on...
View 4 Replies
View Related
Sep 12, 2006
I'm having trouble calling a defined range within a VLOOKUP function in VBA. If the named range is located on the same sheet within which you are running the macro, everything runs fine and all is well in the world.
However, after I relocated the range to a separate sheet (a 'SourceData' sheet to tidy up the user interface sheet), I was getting the following error message:
Method 'Range' of object '_Worksheet' failed
The name is correctly defined - Range("DaysInYear").Select still picks up the correct selection - it's just the VLOOKUP will no longer function correctly.
Here is part of the macro's
For I = 1 To NumberOfDays
Range("A1").Value = DateAdd("d", -(I - 1), EndDate)
If Application.VLookup(Range("A1"), Range("DaysInYear"), 3, False) = 1 Then
If Application.VLookup(Range("A1"), Range("DaysInYear"), 4, False) = 0 Then
ActualNumber = ActualNumber + 1
End If
End If
Next I
View 9 Replies
View Related
Jul 24, 2014
is it possible through vba code to determine the macro security level of Excel 2007 and inform the user. I tried the code below , it is executed when the workbook is opened, but it doesn't work.The code below is executed only when the macro security level is "Low". My goal is at least to inform , with a msgbox function, to change manually the security level.
Code:
Dim secAutomation As MsoAutomationSecurity
Dim zLevel
As String
secAutomation = Application.AutomationSecurity
Select Case secAutomation
[Code]....
View 1 Replies
View Related
Jun 13, 2007
I am trying to figure out how to run a macro for 1 particular workbook in an excel spreadsheet. I don't want it run on any of the other workbooks in that file, just the 1. I can't use conditional formatting because I need more than 3 values (if statements).
This is what one example of data in a cell and below is the color I'd like it to turn when I run the macro:
T: 6/1/07
A: 6/8/07
Anything that has a A: (which means an actual date it happened) I'd like the cell to turn blue. If there is an RT: (which means revised target) I'd like the cell to turn red which means it missed it's target date, and has been revised. If it has a TBD I'd like the cell to turn pink (or yellow or any color really). All other cells are just white. I don't know where to find the color codes in excel as well. Other samples of what cells look like are below.
Here is another example:
T: TBD
And final example:
T: 6/4/07
RT: 6/15/07
View 9 Replies
View Related
Apr 18, 2009
I have a macro that asks the user what pages they would like to print on a particular sheet. In the example below, a button will be assigned to pages 1-5 on a sheet and thus the user has the option of printing from page 1 up to page 5. Any page number outside this range will result in an error message and the user will be asked to re-enter the end page number. This is the code I pulled from this forum and partially modified:
View 4 Replies
View Related
May 9, 2014
I'm trying to run a pivot in Macro where the Pivot needs to choose the whole sheet and not a specific range as the data pasted in the sheet may fall in different range or rows however the columns are stable.,
Below given is the coding for that Macro Recording for Pivot.
[Code] .......
View 2 Replies
View Related
Mar 18, 2014
I would like to know why some macro coding put in sheet and some put in modules?? What the different??
View 6 Replies
View Related
Oct 29, 2012
Sub FollowLinks()
Dim i As Hyperlink
If (A1) = " http://www.ecb.int/stats/money/aggre...ng_amounts.zip " Then
OpenLinks " http://www.ecb.int/stats/money/aggre...ng_amounts.zip "
End If
End Sub
I'm really stuck, as I only just learnt VBA yesterday. I'd also like the macro to run when you press a button on the keyboard, is there a way to do this?
View 2 Replies
View Related
Jun 30, 2008
I have searched for a while on VLOOKUP (something I'm not very familiar with but and trying to become more so), And if this wasnt such a time sensitive project I would continue to search. In one sheet, there is a column which includes employee #'s, the next column over is the employee names, next is salary. On another sheet I put a drop down box where you can select the employee number. In the cell next to that I would like to have the employees name come up as well as the salary in the next cell over....something like this
Name Salary
Dropdown w/#'s
Taken from
Emp# EmpName EmpSalary
23123 Joe Smith $50,000
Is this the right time for vlookup...there are almost 1000 names in this sheet?...
View 9 Replies
View Related
Dec 8, 2008
I have a workbook with several worksheets and numerous userforms, commandbuttons and macro's. I want to prevent people from saving over the workbook once they have used it, but allow save as using a different workbook name.
I tried saving the book as .xlt, but then when I reopen it and make material changes, it lets me save over it. I have't worked with templated before, is there something I am doing wrong?
View 9 Replies
View Related
Mar 26, 2014
I have this formula -
=SUMPRODUCT(('[Australia Load Tracker - March 2014 - V2.xlsm]QA'!$E:$E=B4)*('[Australia Load Tracker - March 2014 - V2.xlsm]QA'!$D:$D=$A$2))
Which works perfectly if A2 has the cell value 24/03/2014 however, if i put in $A$2 this value
="02"&"/"&$XFC$1&"/"&"14", where XFC$1 equals =IF(XFD1>9,XFD1,"0"&XFD1) and XFD1 = =MONTH(TODAY())
Which in basic term gives the month value "03"
The cell shows the value 24/03/2014 however does not work with the sumproduct.. is there anyway to get sumproduct to read this cell value as 24/03/2014 as the whole point is so every month I don't have to update anything and it will constantly update...
The only alternative i can think of is quickly making a VBA script to hardcode the cell values for the dates and change the month value for the middle of the cells every month.
View 3 Replies
View Related
Mar 5, 2008
How do I use Find to locate the first occurence of a particular value in a cell, and return the row that the cell is in?
View 14 Replies
View Related
Jul 17, 2013
I'm working on a complex spreadsheet and I'm working on a complex spreadsheet system for pulling and measuring data. My VB programming skills are about minimal/average, so you may see me on here asking various questions . In any case, what I'm trying to do is create isolation macros for "Kickback" data (erroneous). I'm trying to remove data with certain criteria and isolate it on a separate "kickback" sheet for one for taking a second look at. I've made the easy macro of creating a new spreadsheet:
Sub Create_Kicbacks_Sheet()
' Create_Kicbacks_Sheet Macro
' Creates "Kickbacks" sheet for invalid information.
Sheets.Add After:=Sheets(Sheets.Count)
Sheets("Sheet4").Select
Sheets("Sheet4").Name = "Kickbacks"
Sheets("Kickbacks").Select
End Sub
This coding works correctly. The problem area I'm finding is the sorting data. My goal is to look at Columns A and B for certain criteria and either leave it alone, move it to the "Kickbacks" sheet or delete (due to not being necessary in data calculations). Basically, here's a synopsis of what I'm looking for:
if Column A = Y and Column B = Mandatory -> Leave Alone
if Column A = Y and Column B = Best Efforts -> Move Row to Kickbacks
if Column A = Y and Column B = Empty Cell -> Move Row to Kickbacks
if Column A = Empty Cell and Column B = Mandatory -> Move Row to Kickbacks
if Column A = Empty Cell and Column B = Best Efforts -> Delete Row
Here's the code I have in excel (modified from one I found online)... Which only is doing some of what I want it to do:
Sub Moveto_Kickbacks()
Dim r As Range, LR As Long
With Sheets("Data")
LR = .Range("A" & Rows.Count).End(xlUp).Row
Set r = .Range("A2").Resize(LR - 1)
.Range("A1").AutoFilter field:=1, Criteria1:=""
.Range("B1").AutoFilter field:=2, Criteria1:="Mandatory"
[code]....
View 2 Replies
View Related