Replace Filename With Variable In "Activecell.FormulaR1C1=" Expression
Feb 27, 2009Replace filename with variable in "Activecell.FormulaR1C1=" expression
I have recorded a macro which contains several lines of code like this one:
Replace filename with variable in "Activecell.FormulaR1C1=" expression
I have recorded a macro which contains several lines of code like this one:
I want ActiveCell.FormulaR1C1 = "=SUM(RC[1]:RC[48])" to be added to the VBA code not an activecell.
Total_Sum = "=SUM(RC[1]:RC[48])"
I am currently using a SUMIF statement as follows: =SUMIF(W1:W1500, "Charnwood" & "*", S1:S1500). The problem i am having is the fact that SUMIF doesn't work with a reference to a closed worksheet. I tried using SUMPRODUCT but it did not work. The reason it didn't work is because I need to find in column W anything with Charnwood and anything else past it, auch as Charnwood Estates. This is what I tried: =SUMPRODUCT((W1:W1500="Charnwood")*(W1:W1500="*")*(E1:E1500="S"),S1:S1500)
which of course is a syntax error.
I have to many refrence links I need a macro that replace the filename. How to replace workbook refrence filename on a formula using cell value,
example:
from [13.xlm]2014.Goals'!C8 to ["cell-value".xlm]2014.Goals'!C8
I'm working on a project where I need to populate a column with vlookups taken from different workbooks, I have for the most part got it working. However currently, everytime it populates a cell it prompts the user to select the sheet from the workbook as there are two. The sheet name is always the same so I tried to add it into the code so it would avoid having to repeatedly click okay while it populated the table.
This is the original code where it asks for the user to select the sheet every time.
[Code].....
This is what is produced when it is run and the user selects the worksheet each time (which works perfectly fine):
[Code] ...........
I tried to enter the Full Costs sheet name into the code like so:
[Code] ......
However this produces the following:
[Code] .....
The issue I have found is that the square brackets that are around the filename are generated automatically, they aren’t in the actual filename and I haven’t put them in, so I am struggling to work out how to add the sheet name in where it wont be included within the square brackets, as that is what's breaking the lookup.
I'm working on a spreadsheet that will access two weeks worth of data at a time. Is it possible to have the filename reference contain a variable or a link to another cell in it?
For example: ...
I have a filname called ex: "Statusreport xxyyzz.xls"
I'm only interested to put xxyyzz in a variable and reuse it for saving another workbook.
How can I use the different string functions for this. The word "Statusreport" is used for apporx 20 different workbooks.
Have a file lets say is named
sample.xls
Does anyone know how to retrieve the name of the file in VB?
just the name and put it in a string?
Private Sub cmdImport_Click()
Dim exportFile As String
exportFile = "c:jpmimportTrinity_ImpImport_" & Format( Date, "dd-mm-yy") + "_" + Format(Time, "hh:mm:ss") & ".csv"
Open exportFile For Output As #1
I put a watch on exportFile and it's correctly set to: "c:jpmimportTrinity_ImpImport_15-02-07_17:55:01.csv"
However if I try to run this I get "bad file name or numer" when I open for output - the path exists and I can write to it, so must have a fundamentally wrong approach.
Does this code copy all cells from the active cell up to the last non-blank cell, or is it up to the first blank cell after the last non-blank cell?
View 9 Replies View Relatedreferencing 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
I have a VBA form that the user enters information into and once they click submit on the form the code opens a new workbook and then enters the information from the form into that workbook. What I need is for that code to then save the workbook with a filename from one of the fields entered into the form but I'm not too sure how to do this.
View 3 Replies View RelatedI am trying to get a module wide variable to provide the current filename to the various subs.
View 2 Replies View RelatedMy current dataset goes to row 256, when I use the Macro Recorder it produces the following "static" code.
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"claim_export!R1C1:R256C23", Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="Sheet5!R3C1", TableName:="PivotTable1" _
, DefaultVersion:=xlPivotTableVersion12
QUESTION/PROBLEM:
Each month the amount of rows could be different (columns should be the same)... I have tried (3) different ways to replace the 256 with my variable name called "numbers"
SourceData:="claim_export!R1C1:R " & numbers & "C23" OR
SourceData:="claim_export!R1C1:R[" & numbers & "]C[23]" OR
SourceData:="claim_export!R1C1:R[" & numbers & "]C23
They all produce the same resulting error:
Run-time error '5': Invalid procedure call or argument.
Note* I am sure my variable is working, because when I "step into" (F8) my code and hover over my variable I can see it showing the number I expect.
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.
I am attempting to use the Find and Replace code you assisted with me into another project, But I am missing something. I keep getting a Variable not define error when I go to search for a CMM # in the add a referral form.
Highlight in yellow is the code ...
I have never used VBA in word before, so I am assuming I am making it more complicated than it needs to be. I have a macro that stores 20 excel values as variables, then opens up a word document. I want to replace values in word with my values in excel. I keep getting an error with the replace part. I do not want to use bookmarks or mail merge. MSWord is a reference in excel VBA.
Code that stores excel variables (Example: Var1=Data1 and Var2=Data2)...
'Opening up the correct word document
Dim WdApp As Object, WdDoc As Object
Set WdApp = CreateObject("Word.Application")
WdApp.documents.Open ThisWorkbook.Path & "" & Range("D1").Value & ".doc"
WdApp.Visible = True
[Code] ..........
I have a dropdown box containing text strings. How can I use the selection from a combo box as part of a formula?
So for example I have a spreadsheet that is set up using a search term 'media', I want to select something else from the list e.g 'arts' and I want all of the references to 'media' to turn into 'arts' in the formulas. Kind of like a mass find and replace.
I'm trying to work on a macro that will copy two cell ranges (name of current month and prvious month) from one location, store it as a variable and use that variable to find replace similar text string in another tab. Below is my code which is not changing the values in another tab...
Dim OldMonth As String
Dim NewMonth As String
Sheets("X1").Select
[Code]....
I have the following array function that I am trying to get to work properly:
ActiveCell.FormulaArray = "=SUM(IF(NCR!O2:O100=39326,NCR!Q2:Q100,0))"
39326 is the value of 9/1/2007, and this formula works properly.
I am looking for a way to use this formula but replace 39326 with whatever date is in the first row of the same column as the active cell when it is run.
That is, if the macro was run with cell B8 as the active cell, "39326" would be replaced with whatever value was in cell B1.
when i am doing the coding
may i know if there is a way to replace the cell address $A9 below: ...
I want to count the number of cells in a row containing a value greater than a fixed number but less than a number entered in another cell.
For example, in the cells A1..K1 I want to know the number of cells which have an entry greater than 7 but less than the value I have entered in cell M3. I have used the COUNTIF in other circumstances but I cannot find out how to use it with this "greater than and less than" condition?
I'm having trouble with the Rmdir statement.
I have tried ...
I'm trying to make an expression to calculate some fields in Excel 2007.
Trying to check fields up to a given number and give them a high multiplier, and add the rest of the numbers with a lower multiplier.
I have multiple fields with numbers in hundreds. I want to multiply the sum of this fields (up to 500) with 4. But the expression must also start the count from the first field, and when im hitting 500 as a sum I want the rest to be added with 2 as multiplier (the reason for the prioritizing of the fields is that they also have their own values/multipliers, but I'll skip that to avoid to much confusion here).
It's probably a lousy description. I'll give an example:
Field 1__Field 2__Field 3____Sum
100____300_____500______2800
How in earths name did I get that Sum you might ask.
((100 + 300 + 100) * 4) + (400 * 2) = 2800
400 is the number left from the third field wich I only want to multiply with 2 instead of 4.
Another example:
Field 1__Field 2__Field 3____Sum
300____600_____500______2000
((300 + 200 + 0) * 4) + (900 * 2) = 3800
900 is taken from the rest value of field 2 and 3.
If there any way of doing this "sum check and multiply, and then add the rest with a different multiplier"?
With Excel you can do If(array, array2, false) to poplulate another array. Is there a way to replication this without looping. For instance can the IIf hold an array as its expression or is there any other way of replicating this If statement without looping?
View 4 Replies View RelatedI want to apply regular expression for password
a) The first letter cannot be number
b) the password should have a combo of numbers letters and one special character
c) The password should begin with a big case letter
Here's what I need to do. I have a list of row numbers in AA2:AA6, so for i =1 to 5
I want to insert a page break before cell (column AA and Row(#in cell AA2-5))
what the long expression for the range being summed below.
Reason: I need to exclude some cell values.
I'm trying to figure out the whole Regular Expression thing...so I figured Hotpepper's EXDATA UDF would be a good place to try and rewrite with Regular Expression...I got it to work...but not sure why as it seems opposite of what I would have expected...
eg pattern [^/d] i thought would give me everything except numerics...but it appears to be giving me numerics....
here's the code and sheet...can someone help explain what's going on? .......
Using Excel 2007 the below code causes Run Time Error '16', Expression too complex.
It works fine in Excel 97, 2000 and 2003.
why this would now cause an error?
My search on google only refers to this error in relation to charts.