Why Some Macro Coding Put In Sheet And Some Put In Modules
Mar 18, 2014I would like to know why some macro coding put in sheet and some put in modules?? What the different??
View 6 RepliesI would like to know why some macro coding put in sheet and some put in modules?? What the different??
View 6 RepliesI 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
If I put:
Sub t1()
Worksheets("sheet1").Cells(1, 1).Value = "abc"
End Sub
on sheet1, it works. But if I put it on module1, then it does not work. What do I miss here?
Sometimes I will copy a macro to a different workbook and then modify it to do what I want instead of writing it new.
If it has a reference to a different macro, I have to go through each module in the "VBA Project" to fine it and see what it does.
I was wondering is there a way to fine a sub routine in a project without scrolling through each module to fine it? (without going back to the workbook and clicking on the view macro button)
Also is there a way to alphabetize each sub routine in a module so it can be found easier
I've started to group my subs better so I can find them easier, but there are a lot of old ones.
I just learned that I can name each module.
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".
In my userform I have a lot of textboxes. When the user clicks "OK" the values of these textboxes are transfered to row 3 of sheet1.
For this I use some of the code below:
Code:
If NaamTextBox.Value = "" Then ActiveCell.FormulaR1C1 = " " Else: ActiveCell.FormulaR1C1 = NaamTextBox.Value
ActiveCell.Offset(0, 2).Range("A1").Select
If GroepComboBox.Value = "" Then ActiveCell.FormulaR1C1 = "" Else: ActiveCell.FormulaR1C1 = GroepComboBox.Value
ActiveCell.Offset(0, 1).Range("A1").Select
If TypeTextBox.Value = "" Then ActiveCell.FormulaR1C1 = " " Else: ActiveCell.FormulaR1C1 = TypeTextBox.Value
ActiveCell.Offset(0, 3).Range("A1").Select
If TypecodeTextBox.Value = "" Then ActiveCell.FormulaR1C1 = " " Else: ActiveCell.FormulaR1C1 = TypecodeTextBox.Value
This goes on for about 55 columns. Also, not every column is used as you can see in de code above.
It seems to me that this is not smart coding, so my question is: can you make this more efficient?
I did find some nice code with uses EmptyRow (find first empty row) but in my case it's always row 3 where de input is placed. After this row follows much more data.
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
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] .......
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?
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]....
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 View RelatedCan i know how many modules can be used in a VBA Program
View 9 Replies View RelatedI'm wondering about class modules and what they can be used for etc etc? i want to continue developing my VBA and feel that this area is the next step?
View 2 Replies View RelatedI have managed to get it almost done with lots of help from here the last issue I have is this:
The module I want transferred is working the assigning of the macro within that module to the button is working, however, when it gets to the FillSalesSheet section it opens the said workbook but then jumps to the module and the FillSalesSheet in that.
Module 1 which I would like ignored on the newly formed workbooks looks like this: ...
It seems like I am asking a question at least once a day. I searched the net and forums and could not find an answer to this question. Thanks to everyone for the help I am making a lot of progress because all of you. Basically, I have a read-only workbook which the user gets a prompt to save as a new workbook for editing purposes. I have a autorun macro so now when the user opens their workbook, it contains my autorun macro. I do not want this. Is there a way to remove modules so that the users copy has no macro information?
View 9 Replies View RelatedI have two modules I wish to run when I open a workbook. The reason I have them as modules is they are required to be run manually, also.
Is it possible for me to set a Workbook_Open() sub that will run these two modules?
The modules names are Module1 and Module2.
The modules stipulate what sheets etc they have to act on, I only need the modules to be initiated.
I'm trying to produce a spreadsheet that pulls infomation from different web pages throughout the day. It needs to pull quite a large amount of information from different web pages hence I wanted to produce a subroutine which could be called with different variables for each web page, i.e. url, field, destination, etc.
To actually produce the query I recorded a macro and then used the code it produced. I then changed the URL to url, a string variable which holds the urls of the pages. The destion address was changed to destination, a range variable to store the destionation location, and the webTable was changed to table also a string variable to store the table number. This is shown below.
With ActiveSheet.QueryTables.Add(Connection:= _
url, Destination:= destination)
.Name = "q?s=%5EFTSE&m=L_137"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True.............................
I had a search and look around, but couldn't find any information on how to quickly (automatedly) export all the modules in a workbook to text files.
View 3 Replies View RelatedI was looking for code that actually deletes ALL modules in the VBA code after I terminate a particular program.
View 2 Replies View RelatedI'm trying to make it so that a lastrow I defined in one module will still be defined in another macro.
My background for this - my macro is too large for one module, therefore, I split it in two. However, the new module uses defined variables (multiple lastrow definitions) from the original module.
So, is there a way to make it so when I originally define a lastrow in one module, other modules will recognize it?
I have a number of modules that I want to call is it possible to call them from an array
For example
myarray = Array("Outstanding_Per_Agent", "Unique_Records")
Call myarray
This doesn't work as it says it expects a sub function or property
Do I need to define "myarray" as something or is it even possible.
I'm working with a substantial amount of code (which, due to its size, has been spread out into different modules). Whenever I transition from one module to the other, I have placed a msg at the beginning of each module to prompt the user to simply insert an integer to signify which version of the automation that is run. The following is an excerpt of a sample msg
[CODE]
Dim Msg, Title As String
Dim MyInput As Integer
' Define message."
[Code].....
Where, whatever report is being run, will be the same throughout all of the modules (for example, if you run the "Day" Report" at the beginning, the rest of the automation should be run using the "Day Report" code, not the "Night Report").
Is there a way to do one of the following
1. Label the input of "Day Report" or "Night Report" at the beginning of the automation (where the above except of code is how that would be done), and that can then be the determinant through the rest of the modules
2. Set my code in a specific module to, when it completes, automatically go to the same style of report (Day or Night) in the next module.
Can you run 2 modules at the same time on the same worksheet.
View 2 Replies View RelatedI have successfully rewritten all code in one workbook project. I have cut my Standard modules from 17 to just 4 modules.
Is there a way to remove all 17 modules at once so I can replace them with the 4 new ones?
I know that right clicking on the module and then click on "Remove...." will do it, but I would have to do that 17 times.
Not too bad if this was just one workbook to do. I have about 10 other books to do the same thing to. So that would be doing the right click 170 times.
I'm not even sure if this is possible. And if it is, I was thinking at probably having the code in a workbook open event to delete the Standard Modules??? Then I could just import the new modules.
I created the following sub to signal when a macro in Module 1 is complete:
Public Sub Done()
Dim complete As Boolean
complete = True
End Sub
I placed this just before the end sub in the macro for which I am trying to detect that it has finished executing:
Call Done
End Sub
In the Sheet 1 Module, the code fails at the statement:
If complete = True Then
The error returned is "Variable not defined." All three subs are declared as Public. Why does the Sheet1 sub not recognize the variable "complete" from the Module 1 macro?
I want to set a variable for the range I want to copy so that the range can change between modules Sometimes I want to copy a1:x1 and Sometimes I want to copy a1:m1 what I did but it did not work
Dim myrange As range
myrange = a1:x1
range myrange.select
Selection.Copy
I would like to protect the VBA modules I have written in a spreadsheet. Is there any way of password protecting these (as there is with Excel workbooks/worksheets) -such that users can not see the VBA code unless they enter a password?
View 4 Replies View RelatedI have two different modules in my automation - to be specific one module to convert file from LH to RH and another module to do the reverse - convert RH to LH.
I have put up a radio button choice for the user and based on which radio button is selected would like to run that particular module.
Below is my code. It always throws an error "expected variable or function not module"
VB:
Option Explicit
Public Sub MAIN()
If ThisWorkbook.Worksheets("FRONT").OptionButton1.Value = True Then
Call LH_to_RH
[Code]....
I am following the correct procedure to call modules. A few minutes of search said the modules have to be public sub routines
When I try to open a worksheet that has any sort of macros I get the "error opening file" popup with the request to send the error to Microsoft.
When I check the box to "recover and save file" and proceed I am told that repairs were necessary to save the file
The repairs stated are " LOST VBA MODULES" and "LOST ACTIVEX CONTROLS"
I have not changed anything to my knowledge.
Changine the macro security settings to low has no effect either
I want the macro in this way. All sheets of the workbook. The name of the worksheet to a new workbook save as. But the modules do not get deleted.
View 1 Replies View Related