Use String-Variable In Formula
Sep 16, 2009
if it is possible, to use a string variable in a Formula via VBA.
For example: ActiveCell.Formula = "=SUM(Sheet3!strVariable)"
Of course the code is not working that way. The Variable has the following structer: CellAdress;CellAdress;CellAdress... so it would perfectly fit into the formula-syntax.
Is there any possible way to do that? The reason behind it is, that I have to deal with a flexible range and I want to process this range with a formula. Actually the range is flexible, because of different filters and I only wanna count all numbers in the unhidden rows.
My varibale would then contain all celladresses, for the visible cells.
So in a nutshell: is it possible to somehow use a varible in a formula?
View 9 Replies
ADVERTISEMENT
Apr 21, 2006
Just a quick question, is it possible to use a string variable in a Excel formula (in VBA)? Im trying to do the following in VBA
mortgageSchedName = acName & " Schedule"
Range("B6").FormulaR1C1 = "=mortgageSchedName!RC[254])"
the above results in an error because there is no such sheet as "mortgageSchedName", but I want it to access the value of that string variable.
View 6 Replies
View Related
Jan 16, 2013
I'm getting the generic 1004 error on the Range.FormulaR1C1 line, but I can't seem to see the problem.
Code:
Sub UpdateFormulas()
Dim stockFund As String
For i = 2 To finalRow
[Code]....
The mouse-over on the stockFund variable in that last line shows the correct cell address as the value and I checked the If statement to ensure it actually finds the number. I would guess that it would be a syntax error with that line, but it looks correct to me.
View 8 Replies
View Related
Jul 19, 2012
I've found several posts about returning variable substrings that dealt with one or two spaces, but I have not been able to find anything that is for multiple spaces. The number of characters before the substring will remain constant.
For example:
Income from transmission agreement - 83 subs @ $0.44
In this case I need to extract: 83
Income from transmission agreement - 10,312 subs @ $0.50
Need: 10,312
View 8 Replies
View Related
Dec 7, 2008
I am trying to develope a "goto" page macro where the page value maybe 1,34,7A, 256C etc. I am not clear on how an inputbox value can be compared to a string variable or a numeric variable at the same time. This is what I have done, but when the texboxvalue is "7A" it doesn't work.
View 3 Replies
View Related
Nov 10, 2006
Say you define a public range variable called Inputworksheet and you set it to refer to the worksheet called Inputworksheet. You have a separate string variable with the value Inputworksheet. How do you get this string variable value to call/control the range variable Inputworksheet?
I am getting an excel worksheet value from a lookup function that corresponds to the name of a VBA range variable. Once I have this worksheet value, I would like to use the range variable that has the same name as the worksheet value.
View 5 Replies
View Related
Feb 18, 2014
I'm using a userform to create a new sheet. The form already creates the sheet and names it what was typed into the userform. Now I want it to place that variable in a cell along with a string. the following code will place the variable from the form (tbname) into cell b5.
View 2 Replies
View Related
Oct 30, 2008
I understand that a everything is already considered to be string, but how would I phrase this?
If txtBolow = (a statement which indicates the textbox is full) Then
txtBolow. SetFocus
txtBolow. SelStart = 0
txtBolow. selLenght = Len(txtBolow)
If txLowl = ("") Then
txtLowl. SetFocus
txtLowl. SelStart = 0
txtLowl. selLenght = Len(txtBolow)
What would I use to indicate that the user has completed the data in the textboxes, and the old data is highlighted to make way for the new?
View 9 Replies
View Related
Aug 13, 2009
I am trying to use a variable for the name in the Sheets command so that I can put in the names of the CSV file that I have captured in a variable. Here is the macro that I recorded using Excel 2007:
View 4 Replies
View Related
Dec 24, 2009
I believe I should use the INSTR function, but I simply dont understand its use very well. I have a string in a cell, "MEAS/SPHERE,F(QUA_1),5", the characters I need start at the "(" and end at the closing ")", ref: (QUA_1). The start and end will always be the same, the length of characters and the spelling of characters be anything. Thus, QUA_1 can be CAL_1, CAL_2, SOMEOTHERTEXT_1 or 187bgo_199, etc, always enclosed in "( )". I wish to place the characters and the closing "( )" into a variable as a string.
View 5 Replies
View Related
Jan 8, 2010
CALIB/SENS,S(S5a90b-90),FA(CAL_15)
This one has two sets of quotes, with the information from the noted post I can retrieve the string "S5a09b-90", now that I have a double set of brackets "( )" how do I get the value for the second set of brackets, "CAL_15"?
In the quoted string, CALIB/SENS,S, is constant. The first set of brackets are constant (string length is not), the second set of brackets are constant (string length is not).
View 7 Replies
View Related
Dec 8, 2006
It's been a long time, but I use to parse a string in C.
How do you strip off the long directory path of a string to just the filename and extension?
String Example:
S:2006 jobs602f EID Bass Lake Recycle BPSConstructionSubmittal Review16940-Instrumentation602f-16940-01.rev.doc
Wanted result:
0602f-16940-01.rev.doc
View 9 Replies
View Related
Oct 20, 2009
I have a string variable contacting a file.
I want to set a workbook variable to this file, WITHOUT actually opening it!
ie:
DIM wb as Workbook
DIM filenm as String
filenm = "C: empdata.xls"
set workbook = filenm
============================================
So I know this won't work, but is there anyway around it? (bearing in mind I don't want to open the file!
View 9 Replies
View Related
Feb 9, 2014
i just wanna extract the date shown(last data until meet the first comma) in first column to another column.
column 1
abcde, 1234
abcd, 12345
abcdef, 123
column 2
1234
12345
123
View 3 Replies
View Related
Aug 2, 2014
I have several words in sheet2.one word per line. every line in sheet1 should be checked and deleted if the line (colum 3 and 4) contains any of the words in sheet2. i decided to go with two for-loops, my Problem is a error in line 7 and 9 (indicated by arrows). it seems to me that ...Cells(...).Value is not allowed for strings. i already tried .Text, checked several VBA Forums but could not find a solution.
View 13 Replies
View Related
Oct 24, 2011
I have the following code.
Code:
ActiveSheet.Range("$A$1:$AF$" & lngRows).AutoFilter Field:=x, Criteria1:=Array("ELDU238", "ELDU239", "ELDU240", "ELDU241", "ELDU242", "ELDU243", "ELDU244", "ELDU245", "ELDU246", "ELDU247"), Operator:=xlFilterValues
The values ELDU238 - ELDU247 are values in a column beginning at A2. I want to create
"ELDU238", "ELDU239", "ELDU240", "ELDU241", "ELDU242", "ELDU243", "ELDU244", "ELDU245", "ELDU246", "ELDU247"
in a string variable strArray which will enumerate whatever values are in column A beginning at A2 and create the above. I can then have
Code:
ActiveSheet.Range("$A$1:$AF$" & lngRows).AutoFilter Field:=x, Criteria1:=Array(strArray), Operator:=xlFilterValues
Hence if the number of entries changes e.g. say I have
"ELDU238", "ELDU239", "ELDU240", "ELDU241", "ELDU242", "ELDU243", "ELDU244", "ELDU245", "ELDU246", "ELDU247", "ELDU248"
the code will still work.
View 4 Replies
View Related
Nov 28, 2012
I'm taking some university classes and one of them is called Applications Programming and we have been using excel VBA. I have a project that I'm working on, and it's very basic. Basically we need to create a userform that has 3 option buttons, 4 check boxes, a couple labels and a couple text boxes. It's suppose to be a ice cream selection terminal. Option boxes for basic flavors of ice cream, check boxes for toppings, one text box for user input of number of scoops of ice cream and the last text box to output a reciept/overview of purchase.
So here's the question... I was wondering if there's a way to change the font of a single string variable, or change the font of a word within a string. My output to the saleBox(My receipt overview) is this:
saleBox.Text = ("Thanks you for your Purchase") & vbCrLf & vbCrLf & _
"You ordered " & numOfScoop & " scoops of " & flavorChoice & "ice cream" & vbCrLf & _ "Topped with: " & toppings & vbCrLf & vbCrLf & total
(not sure how the code is gonna look in the message but I'm sure you get the idea)
i want to be able to change the font for the flavorChoice or toppings variables. They are both strings.
Anyways, I know I can get away with basically what I have there and get full marks, but I like going above what the basics are. If it's kinda complicated.
I'm gonna attach a screenshot, more info is better than not enough right... nevermind its askin for a url!
*** I just now got the idea of putting another textbox over the area that would output the text I want to change and hide the border or something and then change the font of that text box through the properties ***
View 3 Replies
View Related
Dec 18, 2012
I'm trying to check to see if a file exists using VBA but the routines I see use a string that has the path and then the file name. I have a fixed path C:VBtesting and the a variable file name. I'm using a file name that consists of a username & date such as cwilliams201212. I'm having problems getting the variable file name into the string.
View 1 Replies
View Related
Feb 12, 2013
I have a comment that I'm putting into a variable for the purpose of obtaining the persons name.
Cell C3 (in this example) just contains their employee number, but it's comment contains...
Tech ID: 123456
Name: John Doe
The Tech ID is variable from 3 chars to 6 chars and obviously the name is size is also variable. The end result will be a variable with just the persons first and last name extracted from the comment.
Code:
Dim mycmt As String
Dim techname As String
mycmt = Sheets("tech").Cells(3, "C").Comment.Text
techname = Right(mycmt, BIG-OLE-BALL-OF-CONFUSION)
MsgBox techname
My 2nd question. This is the 3rd time in recent days that I've needed a partial string and Mid, Left, Right, Len, Find just boggles my mind.
View 6 Replies
View Related
Nov 1, 2013
I'm trying to use a variable that hold a string in Shell string command. This shell is the command to take a snap picture over a given region and store the picture to a pre determined file name
***The code do compile***
The string variable is : StringAddress = "g: estsnapasnap1.jpg"
The following shell command will work
RetVal = Shell(("C:Program Files (x86)HyperSnap 7HprSnap7.exe " & " -hidden
-snap:x3602:y155:w1432:h830 -save:jpg g: estsnapasnap1.jpg"))
This one, with the string address variable, wont work
RetVal = Shell("C:Program Files (x86)HyperSnap 7HprSnap7.exe " & " -hidden
-snap:x3602:y155:w1432:h830 -save:jpg " & StringAddress)
View 1 Replies
View Related
Jan 8, 2014
I'm having trouble setting the Range "UtilizationRange" using a variable, "CurrentRange" to store that range. I get the error "Run-Time error 1004: Method 'Range' of object'_Global' failed".The rest of my code works when I set the utilization range using the actual range for my purposes, but the problem is the range will change each month and I don't want to change it manually each time. There's a cell in the excel sheet this refers to (AG3) that holds the range value, which in this case is [N7:N75], and I would just like to return that value to the variable "CurrentRange" and set UtilizationRange equal to that.
The value is returned to CurrentRange, but it's the last line that's giving me the problem.
Sub RangeTest()Dim UtilizationRange As Range, Cell As RangeDim CurrentRange As String
CurrentRange = Range("AG3").Value MsgBox (CurrentRange)
'This returns the value [N7:N75], which is what I want
Set UtilizationRange = Range("CurrentRange")End Sub
View 1 Replies
View Related
Mar 16, 2009
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.
View 9 Replies
View Related
Jun 12, 2006
Let us assume x and y are strings. Now let us make x equal to a small sentence (ie. full of words and spaces). I now need to somehow make y equal to x, but with the last word removed. I need to do this in VBA.
View 3 Replies
View Related
Jun 22, 2006
I want to remove varying amounts of periods that appear at the end of my strings. For instance, ABCEDFGH......., DEFGH.., FG.... etc. Do I have to test each char to see if it's a period, and then use that count of chars to LEFT out the string that I want? Or is there an easier, quicker way to do this?
View 3 Replies
View Related
Jul 5, 2006
I have a multiple select list box which I capture the selected items by using ListBox1. List
I want to use the 'selection' to build up a string that will form a document name I want to add to an email as an attachment (all being done from Excel), however I get a type mis-match error as the ListBox1.List output is a variant.
So I'm aiming to have something like MyFile = firstpartoffilename & ListBox1.List & "*.doc"
Do I need to somehow convert the variant variable or are there some other clever tricks I can use to create my document name.
View 4 Replies
View Related
Aug 3, 2006
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?
View 3 Replies
View Related
Feb 1, 2007
I have a userform that reads in a list of names into a combobox. When you choose a name from the combobox it then shows the that persons details from a sheet containing all the names.
I have some text boxes that allows the data to be modified and returns it to the sheet which works fine. What i also want it to do it put the data from the form into a sheet for that individual. For example the name of Ford would go into the Ford worksheet.
How do i read in the value from the combobox on the worksheet and use it as a variable to use in my code. For example
Sheets(Value from the combobox).Cells(NoOfRows, 3).Value = Me.TextBoxChangePosistion.Value
*NoOfROws is the variable to find a blank row
View 4 Replies
View Related
Oct 8, 2012
I have a userform with a numerous textboxes, which I have labeled with similar text and a unique number at the end (num1_txt, num2_txt, num3_txt, etc.). I am trying to create a for loop that sequentially references the numbers of the text boxes and pulls the user-entered value in the text boxes into an Excel document.
Here is the code I have so far...
VB:
i = 1
For i = 1 To 18
Dim cyltrack As String
cyltrack = "Me.cyltrack" & i & "_txt.Text"
If Me.cyltrack.Value = "" Then
Cells((cellcount + i), 13).Value = "*"
Else
Cells((cellcount + i), 13).Value = cyltrack
End If
Next i
I am running into problems in trying to convert the string variable, cyltrack, into hard code that I could insert into Me.cyltrack.Value.
View 4 Replies
View Related
Jun 4, 2014
If for example, I have a set of IDs like:
Bellen-234-B25R
Carlota-345-C20RDF
Quad-765-Q20LP
How would I return just the first 4 characters after the second dash? The closest I can get is ALL the characters after the second dash.
View 4 Replies
View Related
Apr 28, 2014
I have a long string that has a list of digits in the middle that I want to extract. The string is variable length and the number of digits I want to extract is 5-7. I also have slashes in between the numbers I want to extract. I need a UDF that allows me to extract the 5-7 digit number from the string and restrict around the slashes (i.e. if two sets of digits in the string match the condition for extraction, extract the one around the slashes.) For example my original data is like
1. aaa/12345/aaa/123
2. aaaaa/123456/aaaaaa/3423
3. 323/aa/1234567/aa
and I want for results
1. 12345
2. 123456
3. 1234567
Is there a UDF that allows me to do this?
View 14 Replies
View Related