Arrays Store In A Macro
May 10, 2008In a cell I will be having many strings separated by a ";" for ex
columna A
a; b; c; d ; e
f; g; h; i; j; k
how to store this in a macro?
In a cell I will be having many strings separated by a ";" for ex
columna A
a; b; c; d ; e
f; g; h; i; j; k
how to store this in a macro?
I have created a number of complex functions that use or create 1-dimensional numeric arrays in VBA, and I would like to store and retrieve some of these arrays within single cells of a worksheet so that I can use them in dependent functions without having to store and display the entire array with one element per cell, and without having to recalculate the same intermediate array multiple times within VBA.
Are there any existing worksheet or VBA functions (or is it possible to create two functions) that can convert and store an entire numeric array within a single cell of a worksheet (e.g., as text), and then convert this back into a form which can be read and recognized as a numeric array by another function?
Or is there any other way to avoid filling my worksheet with arrays, or having to recalculate them each time within VBA?
I have tried to look for this in several websites and have not found the appropiate answers. So i figured one of the Wizards in this board can help me. Right now when I built a macro it has to be dependent to a file. However I like to build a macro button that when I use it, it will actually just work for any given currently open sheet.
View 7 Replies View RelatedI am retrieving a CSV file from the net. In this file there are 'x' amount of row data and 7 columns. I only care about the values in the 7th column for each row. I also don't care about the entire first row. A graphical version would be represented something like this, with the values I want colored in orange:
|---,---,---,---,---,---,---|
|---,---,---,---,---,---,---|
|---,---,---,---,---,---,---|
|---,---,---,---,---,---,---|
|---,---,---,---,---,---,---|
|---,---,---,---,---,---,---|
|---,---,---,---,---,---,---|
.
. extending until the end of the data set
.
I've managed to dice this thing into a jagged array by first splitting it using vbLf as a delimiter, and therefore adding those to an array called Lines(). Then I split Lines() up using commas as the delimiter and threw those into a jagged array, let's call it Breadcrumbs()(). I want to throw all the values from Breadcrumbs(i)(6) into an array of its own. Here's my code so far:
Code:
Public Sub CSVparser(file As String)
Dim Lines As Variant
Dim j As Integer
Lines = Split(file, vbLf)
ReDim breadCrumbs(UBound(Lines)) As Variant
For i = 1 to UBound(Lines) - 1
breadCrumbs(i) = Split(Lines(i), ",")
Next i
End Sub
Is it possible to use the Macro recorder in Excel to store user variables that they put in through a UserForm? So say when a textbox on a userform is changed, it records a macro of what is put into the textbox, which it can then call to retrieve the value.
View 4 Replies View RelatedI have a spreadsheet with near 300 tabs, each with a picture in the tab. The main tab has a list of all other tabs, the goal is to allow the user to click on a cell next to an entry, and have Excel flash the referenced tab to allow the user to see what the entry is referencing. I have written a simple macro that activates a desired tab, unhides it, displays a message box to pause the macro, rehides the tab, then returns the user to the main tab.
Rather than creating a macro for all 300 tabs and creating buttons I would love to use the Private Sub Worksheet_SelectionChange(ByBal Target As Range) or some variation thereof, to make my life much easier. The name of the tab is in cell A2, so I would want to have the user click on cell A1, activate the macro, then take A1 to A2 with something like A1 = A(x+1)->A2, then display the tab listed in A2. So rather than have 300 macros with Sheets("XYZ").Visible = True, I would love it to read Sheets(contents of referenced cell).Visible = True. with the contents of referenced cell coming from some manipulation of the cell I clicked on...
Look at the tab "testing-allproduct" cell C2. If that value exists in the tab name "store-allproduct", cell c2, then take the value from "store-allproduct" cell a2, and put that value into "testing-allproduct cell" A2.
View 2 Replies View RelatedI am trying to write a VBA procedure that uses nested For/Next loops to store the contents of a range in three worksheets to a 3 D array and then input the array into another location.
I have no problem doing this for a 2 D array, but am completely stumped on what changes I need to make in order to perform the same task on a 3 D array.
I will post my code for 2 D arrays below and will also post the uncompleted 3 D code, although, it is currently of no use because I am so lost on the 3 D array.
How do I reference sheet1,sheet 2 etc. when declaring my 3 D array? I know how to reference the rows and columns for my 2 D array by using the cells or range object, but what to do for the different sheets.
Two D Array:
Code:
Public Sub For_Next_Two_D_Array() Dim I As Integer
Dim J As Integer
Dim MyArray(4, 4) As Integer
For I = 1 To 5
For J = 1 To 5
MyArray(I - 1, J - 1) = Cells(I, J).Value
[Code] ........
Three D array:
Code:
Public Sub Store_ThreeD_Array()
Dim I As Integer
Dim J As Integer
Dim S As Integer
[Code] ......
I have some code (listed below) that will open 2 groups of files(for testing purposes, I have been using for only 2 file prefixes, but will need for upwards of 10, and more may be added in the future), depending on what files have been opened in the past (it will skip those) and then import the new ones.
I am now trying to clean up my code, and having alot of it abled to be maintained be editing a spreadsheet (administator controlled)
What I would like to do is something similar to:
defvar= cells(1,1) 'where cells(1,1) has all of the info for that file to import
Selection.TextToColumns defvar
I realize this will probably be a little more complicated than this, and may even be its own sub or funtion.
Here is my starting code, and it works fine: ...
I want to store number as text like green sign display at the top left corner.
View 7 Replies View RelatedI want to store a list of strings in an array with their position so that I can sort them alphabetically and then be able to put them back in their original order again e.g.
John 1
Charlie 2
Paul 3
Andy 4
etc,
So when they are alphabetized (is that a word?) they become
Andy 4
Charlie 2
John 1
Paul 3
My plan was to store them in an array, but I can't think how to do it. In python, I would just make a list of tuples, what is the best way to do this in VBA?
Currently We enclosed a Workbook (with exiting VBA code) In this workbook 3 sheet exit (Edit, Details, Summary)
In Details Sheet store Detail Entry of Invoice & in Summary Sheet we store all generated Invoice details in summary form
We want new VBA or correction in existing VBA.
My Exiting VBA work following..
When Enter Invoice Number in Edit Sheet (Cell B2) then Display Entered Invoice Data
First Code Find Invoice Number in Summery Sheet if Invoice Number found then Record Display of Selected Invoice
Here we Edit As per our requirement then We Press Y in Edit Sheet Cell C30
If Found C30 "Y" & "Data ok" in E30 then DELETE Selected Invoice Data From SUMMERY & DETAILS SHEETS & COPY THIS EDITED DATA (RANGE A33 TO G33 In Summery Sheet & Range A35 to A60 in Details Sheet)
My Exiting code work perfectly as per above
We want only following thing
Currently when we copy edited data that move to end of sheet We want to Change & same place where data exit previously before edited. Because serial number disturb.
NOTE : in Editing Time is it possible Few Item Delete or Few Item Add
Can I store a value with out storing it in a field? -with the macro ending?
Ex macro1 runs and gets A1.value
Stores the value (Not in a cell)
I later run macro2
Gets the stored value
I have a two rows of data one containing names and the other containing corresponding numbers. The names are static and the numbers change on a daily basis. I want to be able to copy the numbers to a static table next to each name on a daily basis (so I can see what the value was a few weeks ago).
Is there anything I can write to do this job?
My thinking was to set a vlookup to grab the data but i'm not sure how this would work because the vlookup would change daily when the numbers change
I'm sure this is a very easy question, but I have been having trouble finding the answer on this and other forums.
Our macro has a search routine where it looks through a column for particular cell contents. Once those contents are found, we want it to save that cell's location, go do something else, and then return to that location afterwards. How would we go about doing this?
I have a simple Excel file with some columns as you can see from here:
[URL]
I have a simple formula (COUNTIFS) to count occurrence of certain condition that I specified. everything works fine here, but I also need to write current value of count cell at the end of each qualified row.
Data entry is random and I may work on row 1 and then row 25, so incremental row numbers that is shown by excel is not my answer. I need exact number of occurrence for each qualified row.
excel.png
I'm looking for is ComplyXL and that costs $300 to buy. So, as a poor grad student, I'm looking for an alternative solution - either a freeware program or a hassle-free VBA code.
So here's what I need the code or program to do: When I ask excel to open a pre-existing file, I'd like it to automatically rename (& compress?) the last used version of the file & save that to a filename-specific archive somewhere (hidden?), before opening the file as requested. Alternatively, I suppose that a mirror copy of each 'just used' file could be created & saved to an archive folder whenever the used file is saved & closed.
--Note: to avoid making copies of EVERY workbook I ever use, I suppose there should also be a button in the toolbar or a file-associated setting that lets me identify which files I want this task to apply to...
Basically I'm looking to have excel automatically save versions of certain key files (like Word's 'Versioning' feature) without having to remember to 'Save As', without the versions taking up much space, and without having to store the older file versions in the same place as the most recent one.
And yes, I know that a similar problem has already been posted & solved here, but they didn't include a way to choose which files used versioning nor (if it's possible) a way to compress the archived versions to save space (maybe by adding it into a WinRAR archive somewhere?).
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 RelatedI want to create a macro that will look at the IE windows that are currently open on my machine, check if the window title contains a certain word e.g. “Results” if so return the full title of the window and store in the worksheet.
I have been searching on the internet for quite some time for this with no real results which leads me to believe it might not be possible.
If it is possible I'm not asking for someone to write all the code for me (I realise how annoying that is!!) but if someone could point me in the right direction or even just tell the code that would return the title that would be great.
I need a bit of help with the below macro which I am trying to create. I recorded the below vlookup, which works perfectly. It checks a list on sheet “Map” and returns a value depending on whether the reference is one of the 6 or not. These 6 are likely to change over time so I would prefer to declare them as variables rather than build them directly into the macro
View 4 Replies View RelatedIs there a Function or Formula that can store data from say cell $J$21 and store the result in L21 in the same worksheet and every time the data in $J$21 changes the result moves down 1 ie: L22 etc.
This would happen at the most 20 times a day.
Is it possible to store format of a sheet in a variable?
I have one sheet. i want to select all cell. then copy the formatting of this sheet(template) in a variable. is that possible? does variable need to be a clipboard? if it is in clipboard how to reference it? i.e if i have two or three formats stored in a clipboard how to select and paste the second one?
once i store this in a variable, i will paste in new sheets(about 50 of them) so that all these new sheets have same format as the template.
what is the easiest to do that?
I have code which is convert some range of excel to Png and store to my local drive. This code is working fine.
I have created web site on my intranet and the data store on server, now i use this code and pickup image from my local storage i.e. from "C" Drive and paste in to service folder, bcoz i uploaded report as a Image and it timely refreshed and changed
Is there any way so this code directly store to service folder, if i can use IP address or HTTP path
I had tried with HTTP path but it is not working.
My server path is [URL] .......
OR
Is there any way when local folder got image than automatically server folder also get same image...
Sub bah()
''' Set Range you want to export to file
Dim rgExp As Range: Set rgExp = Range("B2:C6")
''' Copy range as picture onto Clipboard
rgExp.CopyPicture Appearance:=xlScreen, format:=xlBitmap
''' Create an empty chart with exact size of range copied
[Code] .........
What I am trying to do is during a loop operation, which subtotals variable ranges, I want to store the locations of the cells that it puts the sum function into. I.E. if based on criteria it determines that range E4:E12 is summed into E13, I need to save E13 to use in a formula once I'm out of the loop. I don't know how many instances it will find and there's the possibility in the future that not only will the number of instances increase, but the location could always be different as well. Any way to do this without a million lines of code.
View 7 Replies View RelatedThe problem with the code below is that it re-prompts the input box for each worksheet that the macro runs through.
What I would like to happen is the Input box appear at the begin, and that value is stored and then the same value pasted into A2 on each worksheet.
Code:
Dim ws As Worksheet
For Each ws In Worksheets
Rows("1:1").Insert Shift:=xlDown
[Code]....
1. Store the value in Cell A1 to a text file located in C: with name TEXTFILE.TXT (Replace the existing value)
2. Store the value to the text file as additional line item (append records)
I would like to use array v to store all the results of the for loop u...How can Ido it?
Dim myRange As Range
Dim AnsRange1 As Integer
Dim AnsRange As Range
Set myRange = Application.InputBox(Prompt:="Select row to insert 10 rows below", Type:=8)
AnsRange1 = myRange.Row
Dim u As Integer
Dim v As Integer
Dim var() As Single
v = 0
For u = 23 To 24022 Step 9
var(v) = u
Next u
If Not (AnsRange1 = v) Then
MsgBox AnsRange1
Else
Range(AnsRange1 & ":" & AnsRange1 + 9).Insert Shift:=xlDown
End If
End If
I am trying to do is use a loop to store data from a range into a 3 or 4 dimensional Array and then output the data from the Array in another range. so for example the i want loop through the data in this range and store all data that is in account 701 into an array and then output this information in another range (tab). The data would have several different account but I only want to see one at a time.
Account Price Amount 701 150 1,000,000 701 125 250,000,000 701 3.25 6,000,000 702 4.25 25,000,000 702 2.35 3,600,000 702 2.55 10,000,000
Are there any good website for a beginner on how to set up and store information in excel as a database? I have mutliple sheets that I use everyweek for payroll and I would like to store the previous weeks data in a seperate sheet so I dont have to save each weeks sheets.
View 9 Replies View RelatedIf I have a file open called test file, How I can find the file path of the file that is open and how can I store that's as a variable?
What I am doing is trying to open a file that excel closes in a save as process!