Windows(" " ).Activate Is Not Working With Variable As Input
Feb 1, 2007
I have made a dialog box open using VBA to select some file,
Function FSel()
filetoopen = Application. GetOpenFilename("Document Files (*.xls), *.xls", 1)
Workbooks.Open Filename:=filetoopen
End Function
I need to activate the sheet which is selected in that string "filetoopen".
I am not getting the way to do this ,the normal Windows(" " ).Activate is not working with variable as input.
View 5 Replies
ADVERTISEMENT
Dec 11, 2006
I have the below VBA code that I'm working on where I run it after I already have a workbook entitled BRNewBusiness121106.xls (or whatever day it is when I'm running the code) that's open, and the code opens another workbook, BR-MasterAccounts.xls and then does some work between the two workbooks.
The code is stopping with a "subscript out of range" error at this line:
Windows("BRNewBusiness" & Format(Date, "mm/dd/yy") & ".xls").Activate
Why is it doing this? What change do I need to make so the code will activate that already-open workbook?
david
--------------------------
Sub testAfterDAKCSupload()
'
Application.DisplayAlerts = False
MsgBox "new code follows...deskcheck before putting into production"
'edit the below remaining steps to get working properly
Workbooks.Open filename:= _
"D:B HNewBusinessReconciliationB H-MasterAccounts.xls"
'Sheets("summaries").Range("B7").PasteSpecial (xlValues)............
View 9 Replies
View Related
May 26, 2009
I have created a macro to split out information from one excel workbook into 2 additional workbooks, and format them the way we need. Everything works fine on the filename I originally recorded the macro from, but is giving me a 'subscript out of range' error when trying to run the macro on a file with a different name.
currently, my test file has the 2 following fields that I somehow need to have as variables:
Windows("insmacrotest20090418.xls").Activate
and
Windows("Book1").Activate
I need the filenames and workbooks in the parenthesis to be variable so that the macro can be run on other reports with varying filenames.
View 10 Replies
View Related
Jul 22, 2009
I have .xls files (ex: a.xls, b.xls etc) in a shared drive.How do I get information (run macros without changing anything) from a.xls and create a new file in my hard drive without opening a.xls. I don’t know if that is possible to do. May be sounds very weird. For example, I name this file on my hard drive as a01.xls, b01.xls from b.xls. Now I run other macros from a01.xls. which is active. I want this macros to run independent of the file name the user creates. In otherwords the workbook has to be variable. Not sure how to use ‘Thisworkbook’ function if that is what is needed to do.
View 12 Replies
View Related
Nov 17, 2009
I'm very much in a bit of a pickle. I have updated my operating system from vista to windows 7 and a macro no longer works. The old code is
View 4 Replies
View Related
Apr 29, 2014
I have a macro to collate data from multiple workbooks to a single sheet. The folder path to the source files can be chosen thorugh the macro. It runs perfectly in my system running on Windows XP. But it doesnt run on Wondows 7 system. Both are using MS Excel 2010. In Windows 7 system, while choosing the folder path where source files are located, it says "No items match your search" (screenshot attached). I would want the macro modified so that it runs on any platform. The macros that I'm using is given below:
[Code] .....
Untitled.png‎
View 10 Replies
View Related
Sep 29, 2013
In one Sub() I assign a pathname to a variable. At the moment I am using this to activate the window of a file that is open....
Code:
Windows("OLD LOAD LIST.xls").Activate
But I would rather use this as the file name may sometimes be different...
Code:
Windows(Old_File).Activate
But it isn't working. Is it because I set the Old_File variable outside this Sub() and the variable is losing its contents ? If so, how do I make the variable keep its contents until its changed ?
View 9 Replies
View Related
Mar 23, 2009
I run a machine that scans parts and is able to output the scans into Excel. Each part scanned creates a new sheet, and the number of sheets is variable as the number of parts scanned depends on the size of the lot. Also, since each part scanned is going to have a different number of features, the information being output on each sheet will be variable as well.
I am trying to figure out how to write a macro that will find the first feature, find the values for that feature I am looking for, output a max and min into a final sheet, and repeat for each feature, and for each sheet. I hope this is clear.
View 3 Replies
View Related
Mar 30, 2014
I got this macro from
InputBox Function (Visual Basic)
But it doesn't work, see boldface print.
Code:
Dim message, title, defaultValue As String
Dim myValue As Object
' Set prompt.
message = "Enter a value between 1 and 3"
' Set title.
title = "InputBox Demo"
defaultValue = "1" ' Set default value.
[code].....
I'm also trying to build a macro where I input the cell that I want selected and Excel selects that cell. This is what I came up with.
Code:
Dim s As String
Dim i As Range
s = inputbox("where?")
If s = i Then
Range("i").Select
Else: Exit Sub
End If
View 9 Replies
View Related
Jan 24, 2014
I have code that I just noticed will not work if user inputs a capital S. I have tried a few things but I can not seem to get it to work. Here was the original code:
If Range("H13") "s" Then
I tired this:
If Range("H13") "s" or "S" Then
View 3 Replies
View Related
Feb 14, 2009
My MACRO is used daily to copy data from several sheets resulting in a new sheet with a differing number of rows with every run. My problem is that I need to define this range of rows in order to do an AUTOFILL function.
I know I can use a cell to hold the row count using COUNTA. However, I cannot figure out how to then use the result of this in the range statement.
example using COUNTA within cell D100 produces a row count of 95
My MACRO needs to do the following:
A1 =Month(C1)
B1 =Year(C1)
Range("A1:B1").Select
Selection.AutoFill Destination:=Range("A2:B????"),
View 9 Replies
View Related
Apr 10, 2013
i know i have done this before but im totally blanking. I want to user the inputvalue in procedures called from controller, but it just shows as empty.
Code:
Sub controler()
Static inputvalue As Long
inputvalue = InputBox("Please set min size of trades.")
'other macro's called here
end sub
View 4 Replies
View Related
Oct 12, 2009
Example:
Order Number from VendorOrder Number from SupplierTracking Number from Supplier12345123451ZABCD13456134561ZBCDE134561ZCDEF14567145671ZDEFG1456714567
In these three orders, the first order nubmer has a 1-to-1 relationship with a single tracking number. In the second, there are two different tracking numbers associated with one number from column A. In the third, there is only one tracking number but three different lines of the same order number that need to be updated with it.
The question is, is there a way to line up data fields head to head even when there are variable inputs like this?
View 15 Replies
View Related
Jul 17, 2007
I have a Workbook containing a list of records. I'd like to create some code to
1) Get the user to input their initials when the workbook opens, and capture the response
2) Clear any filters currently applied
3) Apply filters to a non-continous range of columns
4) Apply the input response as the criteria to one of the columns, and 'blanks' to another 2 columns
Private Sub Workbook_Open()
Static varUser As String
'sets varUser variable as String & stores it
varUser = InputBox(Prompt:="Enter Intials (leave blank to view all)", Title:="Login")
'Activates input box to capture value
Dim ContractsSheet As Range
Set ContractsSheet = Worksheets("Contracts").Range("A1:AA999")
ContractsSheet.EntireRow.Hidden = False....................
View 4 Replies
View Related
Feb 21, 2012
I have had this problem in multiple different macros so I will just provide an example of relevant code:
Code:
For J = 0 To 3
Select Case J
Case J = 0
LikeVar = "a*spk1*E0"
LikeVar2 = "a*spk1*E7"
End Select
Next J
For some reason it skips over the likevar variable assignments even though J = 0 on the first time through the loop. I have tried changing the For line to J = 1 to 3, and the case to J = 1, but it still skips to the end select. Is it not possible to use a select case on an iterator variable?
View 4 Replies
View Related
Nov 13, 2008
I have an Excel 2003 situation I cannot resolve. In one workbook, I have a table of multiplication factors based on a numerical general ledger code. On another sheet, I have a data extract including that code and a cost. In the latter sheet, I need to multiply cost by the appropriate factor based on the GL code - IF Code=X, then cost*factor.
Should be simple, but I have too many codes for a nested IF statement. I also tried a VLOOKUP, but since the codes are numerical, Excel interprets them to be in the thousands, while my factors are 1.xxxxxxx, and since the data being looked up thereby appears smaller than the keys, VLOOKUP will only return #N/A or ?NAME, depending on whether I try to nest it in an IF or not. I also have several thousand records per month to which this needs to be applied, so going manual is not an option.
The calculating is done in column E, the original cost is in column AB, the key (GL code) is in column R, and the GL code range with factors is on the !Factors sheet (column A=Code, B=Description, C=factor).
*I'm running Excel 2003 on WinXP Pro
View 9 Replies
View Related
Jun 6, 2014
I have create an excel formula that I need to input data daily.
Every day, I need to insert a line and input my new data.
Below is my formula
=IF(V159="Skip","Go",IF(P160>0,IF(COUNTIF(C60:D154,">"&H159+3),"Good"),IF(COUNTIF(C60:D154,"<"&H159-3),"Good")))
The problem is that when I insert a line. Most of my variable will change according except C60:D154
As you can see below
V159 change to V160 = This is good
C60:D154 do not change accordingly. How can I make it change accordingly ?? Why it is not changing when I insert a line ?
=IF(V160="Skip","Go",IF(P161>0,IF(COUNTIF(C60:D154,">"&H160+3),"Good"),IF(COUNTIF(C60:D154,"<"&H160-3),"Good")))
View 7 Replies
View Related
Mar 21, 2014
I have a spreadsheet where the start date is manually entered in Cell B1 and an end date is calculated in Cell B3. I would like to have the dates between the start and end date, with a step value of 7 days show in the rows under Cell B3. How do I get this to work?
View 3 Replies
View Related
Jul 23, 2009
I need an action to allow for the random selection of a predetermined series of number codes which represent a given letter.
It is probably easier to look at the attached sheet and the previous discussion to see what I mean.
Previous discussion:
http://www.excelforum.com/excel-work...-of-cells.html
View 2 Replies
View Related
May 10, 2013
how to create a custom function with an unknown/changing number of input parameters?
Specifically, I need to create a function that will calculate the average of 1,2 or more ranges. I can't use the built-in average function as I then need to use the average in my function.
what I have so far is:
function points(current as range, previous as range)
if previous > current then final=1
if previous < current then final=0
if previous = current then final=2
points=final
end function
This works okay if I only only have 1 range of values. but in my worksheet I need to be able to enter =points(a1,c1:f1,g1) and have the function calculate the average of c1:f1,g1 and compare it to a1.
View 6 Replies
View Related
Nov 25, 2013
I want to return the data from a list in a cell on worksheet1 if I input a variable on worksheet2. I need to avoid VBA and pivot tables.
Example, if I put "Expense" in the input cell on worksheet2, I want to return a list of each row that has "Expense" in it on worksheet1:
Worksheet 1 (ColumnA/ColumnB):
Revenue/45,000
Expense/20,000
Asset/43,000
Liability/21,000
Revenue/6,000
Expense/9,000
Expense/11,000
Liability/13,000
Worksheet 2 required output (no row gaps or spaces):
Input cell "Expense" - in A1
List required (A3:B5):
Expense/20,000
Expense/9,000
Expense/11,000
View 9 Replies
View Related
Jun 3, 2014
I have declared a 'long' variable. however; how do I change the variable data type to string if user input is not a number? how do I recognize the user input's datatype?
View 7 Replies
View Related
Feb 22, 2014
I have a spreadsheet with 5 columns. A1 to A5
Entries are made into columns A2 to A5 but only ever one entry across all cells
If an entry is made into A2 to A5 the I need a "P" to be placed into A1
View 4 Replies
View Related
Jul 24, 2014
I am trying to create a macro which gives me an input box. I need to enter 2 numbers into the input box. It would be as follows:
Input Box Msg 1 - "What is your labor cost?" (NUM1)
Input Box Msg 2 - "What is your productivity rate?" (NUM2)
Then I need the macro to take this info and enter it into a formula which changes according to the row which you are on. (I need the macro to work based on which ever cell I currently have selected). The formula would be this if I currently had a cell on row 10 selected:
=(NUM1*(NUM2*$H10))/$H10
So, if I currently had cell L10 selected, and I ran the macro and put 100 in for "NUM1" and 10 for "NUM2" and my sheet had 20 in cell H10, then the macro would enter the number 1,000 into cell L10. If I had L500 selected, then the macro would enter the final number into cell L500 based on what value H500 contained.
View 9 Replies
View Related
Jan 25, 2010
I have a workbook in excel 2003 which I had been running the following macros (listed below). We recently upgraded to Excel 07, and neither are working. When I try to run them, the "debug" option highlights the following line in the sort macro "Range("A2:z" & lastcell).Sort key1:=.Columns(1)". This is driving me crazy, as the macros worked perfectly under the older version of Microsoft. Is there an issue with crossfunctionality between '03 and '07'.
Private Sub Worksheet_change(ByVal target As Excel.Range)
If target.Column = 1 Then
ThisRow = target.Row
startRow = 1
i = 1
Set ws = ActiveSheet
maxRow = Cells.SpecialCells(xlLastCell).Row
maxCol = Cells.SpecialCells(xlLastCell).Column
ActiveSheet.UsedRange.Interior.ColorIndex = xlNone
Do While i
View 9 Replies
View Related
Jun 8, 2014
I would like to know if it is possible to transfer values of cells this way?
I've attached the excel file for easier reference.
View 3 Replies
View Related
Jul 4, 2006
I have to design an input user form (a button that opens an input box or dialog box), which asks user to "Enter number of "columns"".
User enters a number i.e. 2 or 3 etc
It then asks user for the headings of these coulmns and places first column heading in A1 and second column heading in B1, third in C1 and so on ...
View 9 Replies
View Related
Sep 9, 2013
I used to think my excel skills were OK until I started working with userforms but I now realise that I have a long way to go.
I need to enter data from various WEB sites onto a worksheet and at the moment I'm toggling between each web site and the worksheet. What I would like to do is set up a userform which I can enter data from each page into and when finished hit a commandbutton to transfer it to the worksheet.
I'm mostly OK with creating the userform but not sure what code, and where I need to add it, to keep the userform on top of all other windows.
Also not sure if it's possible, I have another worksheet that has a series of hyperlinks that when selected open a web page, I can create a combobox that shows the the display names of the hyperlinks but not sure what code I need to add a commandbutton or some other control that will open the hyperlink.
View 5 Replies
View Related
Nov 6, 2007
way of getting two sheets to scroll together, so when I scroll one window the other one moves too? Some text editors have that future (IIRC UltraEdit does)
I can't find a scroll event in the windows code to trigger a macro to run itself.
I can get around it by using a selection change event which would restrict me to moving around with the cursor keys/Pageup/down, but I've got 15,000 to review regularly in a short space of time and it would be quicker by mouse
View 9 Replies
View Related
Jan 16, 2007
I have put together the following code and it works fine on my PC. However, we are a mainly Mac based company and I nead it to work with a Mac. I am using the Actual ODBC Driver for Mac to give me a ODBC connection. I can do the query in excel but setting it up as a macro just will not work.
Sub Sales_Query()
Columns("C:D").Select
Selection.Delete Shift:=xlToLeft
Range("B2").Select
Dim area As Variant
area = Range("B2")
With ActiveSheet.QueryTables.Add(Connection:= Array("ODBC;DSN=my_database;Description=My................................
View 2 Replies
View Related