VBA How To Read Cells Into Variables/array And Use In String
Apr 15, 2009
I made the formula work great, however I want to cut it down and simplify it and make it easier to manipulate... as opposed to having the filename written every so many times.. replace with a loop instead.... so:
Private Sub Weeklytestt_Click()
Dim varCurDate As String
If DateYesterday.Value = True Then Answer = "1"
If DateToday.Value = True Then Answer = "2"
If DateTyped.Value = True Then Answer = "3"
Select Case Answer
Case Is = "1"
varCurDate = Format(Date, "yyyymmdd")
varCurDate = varCurDate - 1
Case Is = "2"
varCurDate = Format(Date, "yyyymmdd")..........
View 9 Replies
ADVERTISEMENT
Mar 31, 2014
I am trying to do a sort of index match thing using VBA. What I am attempting to do is to use the prefix of a long number and try to find that exact prefix in a string array, and output that string array value. So this is what I have so far as a test:
[Code].....
So I can match the text exactly so if I put PREFIXB in cell A1 in this example, i will get the msg box saying "YES", but if I make it PREFIXB1231k4j3jj1kj32cj, it will display "NO". I want to get it so that PREFIXB will be displayed in the cell that I put the formula in. So if A1 = "PREFIX1AAA100CF" and cell B1 = "=ABC(A1)", cell B1 will display "PREFIX1AAA".
Now the thing is that these prefixes can have different lengths, but will never encompass the exact prefix of another. So if I had a prefix of: PRE1AB, I won't have a prefix of PRE1A.
View 2 Replies
View Related
Sep 9, 2012
I am trying to populate many arrays with the same code using something like this. For this test, assume the following data in A1.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Code:
Sub populate()
Dim firstArr(5), secondArr(5), thirdArr(5), fourthArr(5), fifthArr(5) As Integer
Dim r, c, num As Integer
[Code]....
The above code does not work of course and falls over. I am unsure whether I should try and concatenate with something like this eg "" & arrName(i) = Cells (r,c) or go down a different route.
View 6 Replies
View Related
Mar 3, 2014
How to copy the content of cells from an excell->sheet1 to an string array
View 2 Replies
View Related
Aug 10, 2007
In a Worksheet named "Input" and in Cells "B3:G?" I have 6 number groups. How can I ...
( 1 ) Put each of the 6 number groups into an array when I don't know what the last row number is.
( 2 ) Find the maximum value in any of those cells and attach it to a variable named MaxVal.
... so once I have done this I can then loop through each 6 number group and perform some calculations.
View 9 Replies
View Related
Aug 13, 2008
I have a worksheet with 7 columns and I would like to read this into a 2d array. The worksheet can have as much as 50k rows.
1) is it possible to read 50k rows into a 2d array?
2) is it more efficient to read data into an array for access/manipulation as opposed to a worksheet?
3) can someone show me how to read in a worksheet with 7 cols to a 2d array?
View 9 Replies
View Related
Oct 9, 2007
I have a workbook with about 700 rows and about 40 records on each row. about 2-7 a day of these.
The procedure I currently use a loop for does 2 different things.
1 I collect only a few of the records from the line and place them in a separate sheet .I collect the individual data, identify the ID ( cell F) and then search for the corresponding ID on a nother sheet when I do find it I add the info to the sheet on the last + next row. (I sort later)
2 I collect the entire row and place it on yet a nother sheet.
The whole row has information that is categorised by the content of Cell A (name) so I copy the row and paste it into a separate sheet.
What I would idealy like to do is to copy the entire source sheet into an array once, and then copy the data into each target sheet using a loop to get each record from the array. Using only 1 loop to first read the separate data from the " array row" and place it into the first target sheet (procedure 1) and then switch the workbook and copy the whole "array row" into the target sheet there (procedure 2).
At the moment I read info on 1 row switch to the target sheet and place the information there, then I "copy" the row and switch to the next workbook and paste it there then I go back to the source and do the next row.
Obviously Im no programer and that was the best way of doing what I didnt know how to do better .
Is there a way that a whole row can be stored in an array and then 'copied' onto another row on a nother sheet without reading in the individual cells into separate elements. That would be the worse case scenario but a much faster way of doing what I curently have.
View 3 Replies
View Related
May 19, 2009
I am using the following code to read a formula as a string. But sometimes the use r may forget to enter formula in the particular cell. In this case I want to check if the first character of the string is a Equal-to Sign (=). In case it is then macro proceeds further otherwise a message prompts user to enter a formula first. how to check if the first character of the string is a '=' sign?
View 5 Replies
View Related
Jul 7, 2006
I am trying to create a "macro" that will read values from one workbook into an array based on a key field. If the key isn't present the cells data is not to be stored. After the records are stored i want to test them agains a range in a differnt workbook. If the data compared matches a stored value, leave it alone. If there is no match, a cell needs to be added with a value stating a differnce.
Like i stated i am new at this and have no clue how to compare an data array to a field. Let alone read the values into the array.
View 12 Replies
View Related
May 7, 2008
How do I set a ComboBox list to read values from an array? I tried the following in VBA, but it didn't work....
ComboBox1.List = Array("January", "February", "March", “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”)
View 9 Replies
View Related
Jul 30, 2012
in C a string is nothing more than an Array of characters ending with a null character.
in VBA this does not seem to be the case.I am trying to use the BlowFish code from David Midkiff for some encryption, however the code sometimes fails:
When encrypting a string a string of a specific length should be returned. however sometimes one of the characters of the encrypted string is a null character, and the returned encrypted string (with a embedded null character) is causing me problems. I want to check for the null character and if present redo the encryption. But how do I check for the presence of this null character in a unicode (double-byte) string?
Checking with Len(encrypted) gives the correct length (!) but trying to move each (unicode)character into an array fails when using the Mid() function past the null character in the string.
Now I can use
byteArray() = StrConv(unicodetext,vbFromUnicode)
to get the lower byte of each character into an array easily, but how do I do this for both bytes of the unicode characters?
Using an integer array does not work other than through
intArray(j) = CInt(AscW(Mid(Outp, j, 1)))
which fails on the nullstring in my encrypted text.
I have tried with variants but so far no luck. I thought if the string was entered into a variant then I could also address the variant as an array of bytes, but that does not seem to be accepted by VBA.
View 1 Replies
View Related
Dec 20, 2013
I need to export this to Xcelsius which doesn't support any macros/vba. Btw I can;'t use Row() in xcelsius too.
[Code].....
View 4 Replies
View Related
Oct 2, 2008
I have a class module with several private variables, including one that is an array of a user-defined type. I am trying to set the values of a single element of this array with "Property Let ..." from a string array:
View 4 Replies
View Related
Jul 25, 2006
code to pass a range say (A1:A3) as an arguement among other arguements to a custom function and then reading this as an array inside the custom funtion
View 4 Replies
View Related
May 5, 2006
Is there any way to add together a portion of an array without using a loop or for statement. i.e.) I have a array variable: arrayvar = array ( 1, 2, 3, 4, 5)
is there a way to sum the last two numbers in the array without using
arrayvar (3) + arrayvar (4) or a loop or for statement.
I am thinking something along the lines of worksheetfunction.sum( arrayvar( 3 to 4)) I know that this does not work but I hope you can see what I am trying to do
View 4 Replies
View Related
Mar 27, 2014
I am trying to to work out how to compare two string variables that I can see with my eyes are clearly a match but getting the right syntax to convince VBA they are the same is my issue.The first example is:
Direct Credit 158824 BRANDON DONNA C/ Lak30
the second example is:
Direct Credit 158824 BRANDON DONNA C/ 30 Lake Vue Parade
but that still would not get a match that I can find code for.
i am chasing the "holy grail" in VBA and I will leave the records that do not exactly match to manual processing although i hate to give up that easily
View 2 Replies
View Related
Aug 2, 2006
I have recently come across a VBA macro, which reads from a text box within an excel input sheet, copy the text content, and send it via email. However, when the text content started to go beyond a certain number of characters, the text that comes out of the email, got truncated. I presumed this is something to do with the limitation to the string variables where the string " messagebody$ " which is used to read the text can only take up a certain bytes.
I was looking for VBA help, and somehow, it mentioned something called a variable-length string. Would that be a solution to my problem, or how is that used ?
Sheets("main").Select
ActiveSheet.Shapes("Rectangle 1").Select
messagebody = Selection.Characters.Text
....
email.Body = messagebody
View 6 Replies
View Related
Jun 17, 2013
I am trying to loop through different SlicerCaches but it doesn't seem to work.
Here is the code, I am trying,
VB:
Test_Name = Array("[Test - Test Allocation]", "[Test 2]")
For i = LBound(Test_Name) To UBound(Test_Name)
ActiveWorkbook.SlicerCaches("Slicer_Exec_Function_Summary1").VisibleSlicerItemsList = Array("[Mercury].[Exec Function Summary].&" & Test_Name & "")
The code returns a mismatch 13 error.
When I try it without an array, it works fine.
VB:
Test_Name = "[Test - Test Allocation]"
ActiveWorkbook.SlicerCaches("Slicer_Exec_Function_Summary1").VisibleSlicerItemsList = Array("[Mercury].[Exec Function Summary].&" & Test_Name & "")
View 3 Replies
View Related
May 7, 2012
I want to know if I can populate an array with variables..
For example, imagine I've declared 3 variables a, b, c.. and each variable has been assigned a value (which can change)
now I want to say this:
myArray = (a, b, c)
then I want to be able to loop through myArray and retrieve the value attached to each variable..
View 6 Replies
View Related
May 22, 2012
I have 2 array variables in a block of code which I need to compare to check if the items in the arrays are exactly the same. The arrays are exactly the same size and I can see the contents of the arrays in the watch window.
When I try to run and IF statement as in: IF VARIABLE1 = VARIABLE2 THEN - I get a compile error saying "type mismatch" on the equal sign.
View 3 Replies
View Related
Feb 21, 2008
What would be the best approach/funcvtion to use in excel if I had an array of variables and wanted to match them?
E.g.
1,2,3,4,5,6,7
I would like to lookup up a column and if either of these numbers are in that row to say "yes otherwise "No"
View 9 Replies
View Related
Jun 11, 2009
I need to be able to do a look up in 9 different table arrays using 9 different ranges.
I have attached a worksheet to help explain. My problem is that I can't have 9 IF statements in one formula.
I am not sure how to make this smaller or work.
View 14 Replies
View Related
Jul 22, 2014
Okay, I made an epic fail on a previous post that i turned to Solved, a real error on my part of not fully testing before i posted Solved, basically i was so excited that i'd solved it myself, well partially.
I have the following code in the first sub routine that collects which option button has been selected.
[Code] .....
The second sub routine is per following.
[Code] .......
Unfortunately when i tested this with only one variable myRev(1) it worked fine but when i added more myRev variables 2 thru 4 if failed, so is there a trick to passing an array variable between sub routines?
View 2 Replies
View Related
Sep 15, 2012
What I am trying to do is to automatically build a "tree" diagram representing the links in a huge model which is dynamically configured. What I have a problem with is the following:
The tree consists of layers, I start off with the top layer and for each entry in the top layer I can add all its subsidiary layers and draw links between them, this uses a function which takes as its arguments the node name and its layer number (how far down the tree it is) and the number of items in that layer so far.
So I start at the first item in Layer 1 and there are as yet no layers below it. I start at the first one and add the first item in layer 2 then I kick the function off again and that adds the first item connected to item 1 in layer 2 in the layer below (3) starting at the first one, and so on. When I reach the bottom I go up one layer and add the second item in the bottom layer and so on. When I have added all the connctions to the first item in the next to bottom layer I go up one layer and add the second item connected to the first item in that layer and then add all the items connected to it and so on and so on.
In this way I build up the network exhaustively (to make things more complex more than one item in a layer may connect to the same item in the layer below).
I can do almost all that, the issue I am struggling with is I need to keep track of how many items there are in each layer (as some layer 1 items connect to 1, 2, 3 ...8 layer 2 items and so on). my idea is to keep a running total of these in an array LevelCount(1), LevelCount(2) etc. so when I add a new item to a layer I know where to put it. However I cant workout how to do this final step.
Currently I have a function that draws the nodes below a specified node this and takes the correct value from the array LevelCount(n) by passing Levelcount(n) (where n represents how far down the tree you are) into the function and the function then updates the value of LevelCount(n) (ByRef) so that next time I use it it is correct. That is fine but what I want to do is to is to call the same function from within itself when it adds each node which would make it work automatically - it would keep calling instances of the function until it reached bottom and then go back one step at a time to the top but I cant work out how to reference the right value in the array to pass into the second (and subsequent) instances of the function.
I don't think I can simply pass (n) into the function and in the body of the function set LevelCount(n) = LevelCount(n)+1
I also dont know ahead of time how many layers the model will have, nor can I tell which layer a node sits in as it depends on the links that are dynamically configured.
Beyond this a node can also be subsidiary to nodes in more than one level so it needs to sit at the lowest level - but I suspect if I can work out how to do the first bit i can do this too.
View 7 Replies
View Related
Jun 24, 2008
I am trying to construct an indirect array reference as follows;
Dim A10 As Variant
Dim A11 As Variant
Dim A12 As Variant
For i = 0 To 2
String1 = "A" & (10 + i)
String1 = Cells(6, D1_CNum + i).Resize(2995, 1)
Next
But the above doesn't work, what would be the correct way of creating a reference to an Array using variables to contruct the name of the active Array?
I was hoping String1 would equal "A10", so that on the Cells command Array A10, A11 and A12 would be filled using the value of String1??
View 9 Replies
View Related
Nov 12, 2006
I have a dynamic number of rows each with three colums of values. These varaibles I want to fill an array with but I don't know how.
Now I've just "concated" these three variables into a string and then I intend to split the string into rows by the third comma. (see below)
I think it's easier though to use an array and I really appreciate some assistance. Please tell me also the best way to sort the array. It will be sorted by var_Status which is an integer. (sort order: max positive to max minimum)
PreString = PreString & var_StartWeek & ", " & var_Status & ", " & var_Totalh & ", "
View 9 Replies
View Related
Jun 8, 2007
I am trying to pass a public variable to another module in the same workbook. On Module1 I declare at the top
Public stores
Sub Main()
Dim stores(1 To 100, 1 To 10, 1 To 10)
Reader
...which then calls the procedure Reader in Module2
Sub Reader()
let x=1
let y=1
let z=1
let stores (x,y,z)=activecell.value
I've left out the portions of code that seem irrelevant. When the macro runs, I get a type mismatch error on the "let stores" line. If I move the code from Reader into the procedure Main, it works, so it seems to be an issue with passing the variable. I haven't used multiple modules very often so this is probably a very basic issue.
View 3 Replies
View Related
Mar 1, 2009
On to what brought me here; I have a spreadsheet with a column containing an address, eg '12 SMITH ST SOMESUBURB NSW 2001'. I'm looking at splitting this cell in half after the street and moving the second half (suburb state postcode) into the next cell, which i've managed to do with a series on InStr statements.
Now the fun part is that not all these addresses are streets, some are avenues (AV or AVE), roads (RD), place (PL), drive (DR or DRV) etc. Initially i just did this:
View 7 Replies
View Related
Aug 30, 2006
I work with data that varies in row numbers but is consisten in column width. I am trying to write code that will create a named range for the data but be flexible to expand or contract based on the amount of data that is pulled in. Below is the
Const lngLastPossRow As Long = 65536
Dim strDataRng As String
strDataRng = ActiveSheet.Name & "!R4C1:R" & Range("a" & lngLastPossRow).End(xlUp).Row & "C17"
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
ActiveWorkbook.Names.Add Name:=("Data"), RefersToR1C1:= _
strDataRng
While the result creates a named range called "Data" , it does not allow me to reference and data in any formulas ( sumif's, etc). Can someone tell me what I am missing. It appears to be returning the wrong data type (string as opposed to range values).
View 6 Replies
View Related
Apr 17, 2007
I am trying to automate a report writing spreadsheet in which the text never changes in the cell (up to and over 50 words long).
Is there any way in which the figures within that text could be linked to another cell and change accordingly.
For example: a particular cell might contain the following which never changes apart from the figures:
"the performance of the fund was (B5) followed by a change in the index of (B6)...........the performance of the irish stocks was (A19) etc etc."
I know something can be done in formatting but for very long text would this be impracticle?
View 5 Replies
View Related