Import Variable From Another Function Into Subroutine?
Jan 19, 2014
In these lines of code I am adding hyperlinks to cells in a row. It shows my steps recorded but since there are some 4,000 cells I need a macro to do it automagically. The target cells are in sequential worksheets but in each case follow the sane pattern (i.e. P2, H3, X3, D4, etc.). Could I capture this routine for each sheet by the sub for each? If so how?
Range("B2").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, address:="", SubAddress:= _
"'Max tree base'!P2", TextToDisplay:="'Max tree base'!P2"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, address:="", SubAddress:= _
"'Max tree base'!H3", TextToDisplay:="'Max tree base'!H3"
[Code] ...........
View 1 Replies
ADVERTISEMENT
Dec 23, 2007
My code defines a variable: newrow. Then I call a subroutine using the Call command.
The subroutine does not recognize newrow.
It says it has value zero. How can I pass the value of newrow on to the subroutine.
View 9 Replies
View Related
Jan 18, 2007
I have a code below which need some input from user. This input will also be serve as the input of the subroutine which i am going to call. However, i do not know how to go assign this input to the subrountine which i will be calling, can anybody help ?
For example, the "input" variable will also be served as an input in subroutine test2 ...
View 6 Replies
View Related
May 12, 2006
1. Can a Subroutine be called from within a user-defined Public Function? How?
2. Is there a difference between calling a subroutine with a 'Call Sub_Name' statement, vs. calling the subroutine with an 'Application.Run'(?? or similar) statement?
View 5 Replies
View Related
Mar 11, 2007
I wish to import data from another workbook which will always be one directory level up from the target workbook. The problem is that the source workbook's name will change but it can always have the first four characters the same, ie, List_Dublin, List_Kildare, etc.
View 4 Replies
View Related
Aug 18, 2006
referencing a variable during a data import. I have searched the forums here and the web for a couple weeks and attempted enclosing the variable in many different symbols.
Nothing I have tried works. I have also read chip pearsons guide but I was still not able to get it to work.
I am trying to provide a way for the user to input the filename and location in an input box and then use that variable to import the data. It is only one file that is needed.
The message box filename is only included to allow me to verify the text input.
Dim Filename As String
Sheets.Add. Name = "All Data"
Filename = InputBox("Enter Filename: ", "Enter Filename Location")
MsgBox Filename
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;Filename", Destination:=Range("A1"))
.Name = "SHOAlarmsJune2-9"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
View 3 Replies
View Related
Oct 30, 2008
I have this Macro for Excel which imports 1 file C:datafilesuser1-data-1.txt into cell E52:
View 6 Replies
View Related
Nov 30, 2008
I am working on a project to import cellular phone usage data from Sprint into a workbook.
All cells in Column A are blank. Column B contains 1 instance of the cell phone account #, followed by dates of calls made, which continues until the next cell phone account # appears, and it’s calls made. The # of calls made obviously varies per account #.
The dates are in date format. The cell phone account # is in text format and is formatted with blue fill.
I need to copy the cell phone account # into column A for each line that has a date value in ColumnB, but the value copied must change when it reaches the next cell phone account #, so that the calls are matched up with the cell phone account # and can be imported into SQL.
Acct #
Date
Time
City Called from
State Called From
Called #
City Called
State Called................
View 17 Replies
View Related
Aug 25, 2007
Im creating a cash reconciliation application for a BUS operator client that has 6 depots and 1500 drivers.
each driver is uniquely identified by a special number.
long story short, I get 2 workbooks (named Cash1 & Cash2) that I need to have imported by driver number in my main cash rec workbook named Cashrec.
for example; ...
View 9 Replies
View Related
Dec 14, 2013
VBA jumps out of my called subroutine which is stored in a Module halfway.
When I call the SortLec() sub, it runs until y1 = Application.Match(MC & "-" & CI, rng, 0), and then it just jumps back to the SUB commandbutton1_click() IF statement. Why is it that VBA skips the rest of the code from my sub?
Option Explicit
Private Sub CommandButton1_Click()
Dim i As Integer
Dim numofrows As Integer
Dim workbook_directory As String
Dim file_name1 As String
[Code] ............
View 2 Replies
View Related
Mar 14, 2008
Im trying to call another subroutine within the same workbook but it doesnt work,
---------------------
Sub Macro1()
Dim mac1 As Variant
Dim mysub As Variant
Select Case Cells(1, 3)
Case mac1
Call mysub
End Select
End Sub
---------------------
View 9 Replies
View Related
Oct 27, 2008
in writing a subroutine that needs to ask the user
1) tax file number
2) Income
3) tax withheld
It then needs to use a function that i already made called 'incometax' that calculates 'taxpayable' and use that to calculate taxreturn (difference between 'taxpayable' and 'taxwithheld').
I then need it to output like this in a message box
Estimate for tax file number: .....
Created on ......
Total income: ......
Tax witheld: .......
Tax payable: ......Tax return: .......
View 9 Replies
View Related
May 23, 2007
Is calling a subroutine within another different than running it from the play button in the VB editor? I am getting different results.
I have the following code that I want to call from another subroutine that creates a series of command buttons.
Sub DynamicButtons()
Dim ButtonCount As Integer
Dim ctl As OLEObject
' Create the Button objects
ButtonCount = 0
For Each ctl In Sheets("Sheet1").OLEObjects .............
View 9 Replies
View Related
May 19, 2014
Is it possible to use a variable in Countif?
See attached sheet. When a number repeats for the 3rd time, I need to reset the
Countif function.
For example;
Countif($A$5:A20,A20).
I need to change the $A$5 to the current row number so we can start the count again. I need to do this several times during the sheet.
We are counting numbers until they repeat for a 3rd time and then we start the count again at that point.
View 1 Replies
View Related
Dec 9, 2008
I'd like to compare values from different sheets. My sheets contain data from different years. I have sheets named 2000, 2001, 2002, 2003.... I also have a sheet named "compare". Now I'm using functions like: =('2008'!J13/'2007'!J13)-1
which gives me the relative change between years 2007 - 2008 in the cell J13.
I'd like to use the sheet name as variable. For example: "year 1" is given in cell A1 and "year 2" given in cell A2. Then I could enter (for example) 2007 in cell A1 and 2008 in cell A2. How can I use these cell values in the function? I’ve tried something like: =('A2'!J13/'A1'!J13)-1. I assumed that 'A2'!J13 would be the same as '2008'!J13. It didn’t take me long to figure out that doesn’t work. What would be the right way to do this?
View 3 Replies
View Related
May 29, 2014
MAX function with a variable range. I want find the highest value in a changeable range in a column. The problem for me is, how can I automatically change the range where the highest value is returned.
Here is an example:
Cell A1: 14
In cell A1 is the number entered that specifies the range. In this example the range is 14 rows =MAX(A18:A31).
A2 126.36
A3 126.16
A4 124.93
A5 126.09
A6 126.82
A7 126.48
[Code] .....
Using =MAX(A18:A31) returns 128.57. So far so fine.
But what is the MAX function if the range value refers to the number entered in cell A1? If I change the value in A1 from 14 to 20 how can I make the MAX function flexible that it refers to cell A1 as the range value?
Using the value 20 in cell A1 the MAX function would be =MAX(A12:A31). I can change this manually of course but I want a MAX function that refers to cell A1 as the range value.
I want also mention that the data series is update every day, so that each day a new value is added in column A, e.g. A32, A33, A34. and so on.
View 13 Replies
View Related
Feb 17, 2014
I would very much like to sum a range of values using variables instead of hardcoded ranges. I have tried the following (and variations of )
Range("D2").Formula = "=Sum(Cells(rowIndex1, colIndex1), Cells(rowIndex2, colIndex2))"
where rowIndex1 is starting row number, colIndex1 is the starting column number.....
It does not work.
View 6 Replies
View Related
Aug 12, 2008
I'm playing around with the Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) function. I have a list of people in Column D that I'd like to move data around if the user double clicks on a cell in Column D. The list is about 158 rows long, and could grow beyond that. I've gotten lazy typing:
If Intersect(Target, Range("D4") Is Nothing Then
Exit Sub
Else
{My Code Here}
End If
If Intersect(Target, Range("D5") Is Nothing Then
Exit Sub
Else
{My Code Here}
End If
Etc, Etc, Etc
What I was hoping to do is use a variable (t) to cycle through the rows and call the various functions. So what I came up with is:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Application.ScreenUpdating = False
On Error Resume Next
Dim t As Integer
Dim Subtest As String
For t = 4 To 158
Subtest = "D" & t
I've created Sub D4(), Sub D5(), and Sub D6() as a test. This didn't work at all as it's looking for a Subtest(). Also, clicking on D5, D6, didn't do much either. Is there any way to make this cycle work, or should I keep typing away?
View 9 Replies
View Related
Jan 28, 2009
I've searched for an example of function that returns a variable, however, I'm unable to find one other than the one just has return variable on the end. I was wondering what I have wrong in the following code. This is placed in a module to make it available to all my worksheets.
Public Function findLR(Worksheet, Column) As Integer
LR = Worksheet.Cells(Rows.count, Column).End(xlUp).Row
return LR
End Function
View 9 Replies
View Related
Jan 27, 2010
I need to calculate the max over a range of figures in a macro.
The "from" is a variable, call it X
The "to" is my counter in a loop so (Cells(-(Counter - 1), 5)
What I'm trying to do is to tell Excel that I want the max from X to the current counter cell.
e.g. Application.Max(Application.Index(X, 1):Cells(-(Counter - 1), 5))
but this gives me an error. I also attach a spreadsheet.
View 5 Replies
View Related
Apr 3, 2014
Is it possible to refer to an object which is in another subroutine?
Or should i have to give its definition in each sub i need it?
View 7 Replies
View Related
Feb 26, 2014
I need to allocate an existing subroutine (its code below) to a new button I'd like to add to my sheet. Two questions arise: to use "form control" or "activeX"?, also should I redfine the first line of the code?
[Code] .........
View 4 Replies
View Related
Mar 26, 2009
I want to pass the name of the routine as a parameter.
View 6 Replies
View Related
Feb 20, 2010
My code passes a string created by a function to procedure. It all works great, but i need to add something so that if the string = false then sub doesn't run. What's the best way to do that. Here is some of the
View 6 Replies
View Related
Nov 17, 2013
I met problem in calling into a subroutine. It is error 424. I have dim all variable. However I still get it.
Code:
Sub UpdateAll()
'
' UpdateAll Macro
[Code]....
I got the error when I pressed F8 to step into the getOneRecord() function, which is highlighted in red.
View 2 Replies
View Related
Mar 6, 2008
I have 60 checkboxes on my spreadsheet and basically, when any of the checkboxes are clicked on, the same action should be performed.
The only way I know how to do this is if I were to write the same code 60 times... one for each checkbox_click() method.
View 9 Replies
View Related
Nov 25, 2008
This might be a dumb question but is it possible to pass a boolean variable as a parameter to another function?
I have the following code that produces some compile error ("expected ="):
View 2 Replies
View Related
Jul 24, 2009
I am having trouble using the MATCH function in my code. I am looking for a match in one worksheet from a cell in another. I have defined these cells and ranges as variables. However, it doesn't seem to be working with my application. I would like to find the row of the matching cell and use the output of the MATCH function to determine the next step in my code with an IF function. Here is my code. (NOTE: this is my edited code, I removed irrelevant pieces. The major problem is the MATCH function.)
View 4 Replies
View Related
Aug 19, 2009
How should this read? So SheetName is the variable in the range funtion?
Dim SheetName As String
SheetName = ActiveSheet.Name
Set AllCells = Range('" & SheetName & "'!B7:'" & SheetName & "'!B60000")
View 9 Replies
View Related
Apr 22, 2006
I am trying to produce VBA code that will perform the CountA function on a variable number of lines in a column. My macro first sorts the worksheet by department number and then inserts 2 blank rows when there is a change in departments. Most departments have several rows of data, but some may have only 1. In column N of the first blank row following each department, I want to count the number of rows for that department.
View 3 Replies
View Related