Store The Selected Cell's Address Into A Variable
I have a table in which I have a "patient" column and a "page" column. The macro searches for a patient's number, then looks if this patient has the page "900.--". A patient may have more than one page, which will result in many rows with the same patient number. So far, my macro uses the search function to find a patient number, then compares the cell next to the active cell to see if it contains the page "900.--". If not, then my macro searches for the next patient and so on until the page is found and noted into another workbook or none is found.
In order to stop the loop, I am trying to store the address of the first cell found into a variable "rFirstCell" so that it can later on be compared to another variable, "rSecondCell", which represent the active cell. When both are the same, it means all the available search results have been tested and the loop should stop.
Dim rRng As Range, rFirstCell As Range, rSecondCell As Range
Set rRng = Worksheets("Overview").[a1]
Dim sDeath As String
sDeath = "death"
ActiveSheet.AutoFilterMode = False
If LCase(rRng(2, 15).Value) = "x" Then
If LCase(rRng(2, 9).Value) = sDeath Then
Workbooks("DM Endpoint pages_test.xls").Activate
View Complete Thread with Replies
Related Forum Messages:
Store Cell Address In Variable
I would like to record the address of the last set of cells that data was input into to a variable so that a user can choose to delete the last entry. An 'Undo' button really.
What I have is a user form that writes different materials to thier respective sheets in the database. (Material1, Material2, etc.) Some materials have a different number of variables (some have a width and some don't, but all have a quantity.)
This is the code I have for adding the material to the database (each material has it's own button with material specific code.)
Private Sub AddToMaterial1_Click()
Set c = Worksheets("Material1").Range("a65536").End(xlUp).Offset(1, 0)
Application.ScreenUpdating = False
c.Value = Me.Material1Quantity.Value
c.Offset(0, 1).Value = Me.Material1Description.Value
c.Offset(0, 2).Value = Me.Material1Length.Value
lastentry1 = c.Address
lastentry2 = c.Offset(0, 1).Address
lastentry3 = c.Offset(0, 2).Address
lastentry4 = c.Offset(0, 3).Address
lastentry5 = vbNullString
lastentry6 = vbNullString
Application.ScreenUpdating = True
The following code is what I am trying to do for a single button to clear the last entry to the database.
Private Sub RemoveLastEntry_Click()
Range(lastentry3).ClearContents '(There is always at least 3 cells to clear)
If lastentry4 = nullstring Then Exit Sub
If lastentry5 = nullstring Then Exit Sub
If lastentry6 = nullstring Then Exit Sub
Selected Range Address To Variable
I have created a work diary in Excel which is built up in half hour blocks. I am able to create my appointments (usually one or two hour blocks) by selecting a group of cells and running a macro which merges the cells, colours them and puts a border round them.
I now want to be able to delete individual appointments by selecting the appropriate appointment and running a macro to copy and paste from the same range of cells in another worksheet (which is effectively my blank master diary page).
I have tried work out what code I need to put the range of the current selection into a variable in VBA but I'm not having any luck.
Store Cell Location In Variable
way to store a cell's location to variables.
int a, b
Cell(a, b) = ActiveCell
I'm currently working with a fairly large worksheet, and I'm using Cells. Find to look for a specific cell. Then I want to Filter that column, but I can't figure out what column Selection.AutoFilter Field:=? should be.
Store Variables Selected In List Box Form
how to store the variables selected in a list box for future use in the macro?
I've got code as follows:
This is in my main module
'These set up the global variables
Public SelectedRegion As Variant 'I've also used string
Public NewTabName As Variant 'I've also used string
'This links the list box to the values in a hidden tab named "Regions" and shows the form
WSForm.RgList.RowSource = "Regions!A1:A10"
This is in my coding for the form itself (list box & buttons)
'Code for my "Cancel" button
Private Sub cmdCancel_Click()
Store VBA Variable For Later Use
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
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: ...
Access A Cell's Contents Via A Variable Containing Cell Address??
How can you access a cell's value via a vb variable that contains the cell's address. I have a vb variable named cellAddress (string) that contains "$A$1" and I want to assign the contents of what cellAddress points to another VB variable - how do i Do this?
e.g. if cellAddress = "$a$1" and A1 contains "xyz", I would like to assigne "xyz" to a new vaiable by referencing just cellAddress??? Also - Can anyone reccomend a good Excel VB book? A book that maybe stresses the VB language rather then a cook-book approach.
Variable To Store Multiple Values
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
Store Current Sheet Name As Variable
I have a workbook that is composed of forty (or so) worksheets containing data and a single summary worksheet that has command buttons that take the user to the appropriate data worksheet for their specific project. Each data worksheet is exactly the same in terms of where the header row starts, and the specific headings.
On each data worksheet there is a command button that when clicked, builds a pivot table of the data for the current project. I have been able to create VBA code that hides the columns containing the data and then creates the pivot table in the empty (unhidden) columns n the same worksheet. This works fine, but is not a good solution from a useability standpoint.
What I have been trying to do is when the command button is clicked I want to capture the name of the current worksheet as a variable in VBA, go to a separate worksheet to build the pivot table, and when the user clicks a ‘Review Data’ command button on the pivot table worksheet they are taken back to their original worksheet containing their data. Is this possible?
Store Range Values In Variable Array
I have a list of names from cell A1:A10 in sheet "Input." Each of these names has its own corresponding sheet in the workbook. I want to be able to run the same exact VBA code for each sheet. In other words, I am trying to get my name variable to automatically change to the next value on sheet "Input." I'm sure this is pretty simple to do, but I can't seem to find anything that works!
Prompt To Select File/path And Store As Variable
I am looking for macro that when run, will open a file explorer window and prompt the user to select a folder and file where they have data stored. Then I need it to be stored as a variable and used as a part of a "Workbook.Open Filename" command.
The reason for this is that, I have a huge formatting marco stored within a workbook. When a user extracts a report from SAP, I want the workbook to grab the file that is extracted, open it and import all of the data in order to be formatted.
Concatenate Variable (user Selected) Cells
I want to do a concatenate for multiple fields, but want the user to specify which cells should be concatenated by entering this in a few fields. What does this formula (or VBA) look like?
Let's assume there is the possibility to concatenate a maximum of 4 cells. Call the 3 cells that will be concatenated cell1, cell2, cell3 and cell4.
On the first sheet of the workbook the user enters the following:
cell1 = Sheet2!A4
cell2 = Sheet2!B4
cell3 = Sheet2!C4
cell4 = Sheet2!D4
Here are some cells and their values:
Sheet2!A4 = Hel
Sheet2!B4 = lo
Sheet2!C4 = World
Upon enterring the information after the = sign for the cell1, cell2 and cell3, the formula for the concatenate becomes: =CONCATENATE(Sheet2!A4, Sheet2!B4,Sheet2!C4 ).
The result of the formula is: HelloWorld
If I now change the values of cell1, cell2, cell3, and cell4 the following should happen:
cell1 = Sheet2!B4
cell2 = Sheet2!C4
The formula for the concatenate becomes: =CONCATENATE(Sheet2!B4, Sheet2!C4).
The result of the formula is: loWorld
Elseif Statement In Vba: If The Selected Cell Falls Between 1/01/06 And 31/01/06 Then Jan Would Be Selected
Basically it is a if statement saying that if the selected cell falls between 1/01/06 and 31/01/06 then Jan would be selected. The end part is not a problem; I’m just not sure how to write the one line of code that would test if the cell falls between the two dates. I attemped to create it as shown in the code attached below but wasn't successful. I used an else if statement to test the other 11 months.
Dim SelectDate As Range
Set SelectDate = Range("SelectedDate")
If selectedDate >= 1 / 1 / 2006 And selectedDate <= 31 / 1 / 2006 Then
ActiveSheet. PivotTables("PivotTable1").PivotFields("PnLDate").CurrentPage = _
ElseIf selectedDate >= 1 / 2 / 2006 And selectedDate <= 28 / 2 / 2006 Then
ActiveSheet.PivotTables("PivotTable1").PivotFields("PnLDate").CurrentPage = _
Store Cell For Later Retrieval
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?
Store Worksheet Name In Cell & Use In Formula
I am trying to use the Indirect function to use the value in a cell to select a sheet with the same name as the value of said cell. I have looked at several posts and attempted multiple methods. I still get an error. I cannot find a thread describing exactly what I am trying to do, which is:
reference a cell value to direct the formula to the correct sheet to then complete an array Sumproduct formula.
Since this description barely makes sense to me reading it, I have attached an example. The problem is in cell C7. Basically, I want cell c7 to look at cell c1 and then go to the tab with the matching name as cell c1 and complete the calcuation.
Store Values Within A Cell To Make Them Selectable?
I do data entry for a webstore and one cell is used to map out the exact product category/subcategory path. I currently have to copy the appropriate path from a long list on one page and then paste it into the cell. I have to do this a hundred times a day. It would be nice if each cell within that column can have these values stored in them so I can just click on the cell and open up a drag down box and select the needed value. Is this possible to do in Excel?
Store Values Of Cells With Cell Comments
I have a worksheet where some cells contain a comment. I don't know beforehand how many of those cells are present, nor their address. I want to write a macro that stores the values of only the cells that contain a comment into an array (of course the size of the array is not known beforehand). This should be done by scanning through those special cells in a given order (by rows, by columns, whatever).
Incorporate Adjacent Cell In Formula W/o Naming Cell Address?
I searched and I keep finding something that's not quite what I'm looking to do so I think I'm missing something really simple.
Let's say that I want each cell in col b to be the sum of 5 plus whatever value is in the cell adjacent to it on the left (col).
I know that you can just write a formula in each cell like...
b1 will be =sum(a1+5)
b2 will be =sum(a2+5)
... but is there a shortcut so that you don't have to write out the actual cell address for each one?
Meaning - is there a predefined name or something that represents the cell to the left or right so you can just use that instead, allowing you to just copy paste the same formula all the way down the column? Something like...
b1 will be =sum(left+5)
b2 will be =sum(left+5)
... where "left" represents whatever value is in the cell to the left of that particular cell?
Detect Cell Address Of Cell Directly Under Mouse Pointer
I've a sheet that presents the profitability of sales locations in a geographic layout (similar to Tables in a restaurant), each sales location is a cell, with roughly 1,600 locations presented. Each location is colour coded based on performance / measure, in a basic thermographic way [e.g. dark blue for very poor, solid red for high performance] with users being able to change metrics and re-colour cells accordingly.
The sheet is already information rich, but I'm wanting to detect the cell address directly under the pointer and populate a text box or other cell based on the value in the cell directly below the mouse pointer.
My question is; Is there a simple way of detecting the mouse position on the XL Grid? nb. Want to avoid having to activate cell beneath pointer.
Obtain Cell Reference/address Base On Cell Value
I have this certain value "Y" in all the sheets. In the summary sheet, I would like to get the cell address for this value in a given sheet. I know that you can get cell address using CELL worksheet function. However, for that you need to know the reference to the cell, which is what I am interested in.
I tried Hlookup to get column #. But couldn't figure out how to convert the number to letter so that I can use MATCH to get row # and then finally, index or address function to what I am looking for.
If someone knows how to convert column # to column letter OR knows a better/easier way to obtain cell reference/address based on cell value,
Cell (Address ... )
I have created the below formula to return an address. I need to use this address in the second formula ("cell address here"), If i am completely off base please point me in the right direction..
=OFFSET("Cell Address here",10-$BI$1,0,1,1)
Address Of A Cell?
I have a variable Num that covers the range of C5, C6, and C7. I would like to figure out how to write the code that grabs just the column portion of say C5.
Set Num = Range(Range("C5"), Range("C5").End(xlDown))
Range(Column(Num), 3).Value or something like that
regarding the cell value. What i am trying to do is I have alot of cells with datas and in cell(1,8) I have a data. I will search through these cells and if they match with data of cell(1,8), it will return me the cell (x,y) with x and y being the row and col numbers. Is there any command that I can continue with the below code to get the x and y?
For Each cell In Range(Cells(3, 4), Cells(500, 26)
If cell.value = cell(1, 8).value Then
Formula Reference Cell Address In Cell
I have 2 sheets. In the first sheet, I have 3 columns. The first column contains transaction codes. The 2nd column contains the destination code (like a mapping cell where the value of the 3rd column would go but in a different sheet/2nd sheet) and the 3rd column contains the values for it. Would it be possible to reference a destination in a cell itself? Or should I just code it individually? I wouldnt want to reference each data one by one because the total would be 480 reference cells. Is there an easier way?
Hyperlink & Cell Address
I'm so close to having this figured out, I use the formula =HYPERLINK("#Reps!"&ADDRESS(MATCH(9.99999999999999E+307,Reps!C:C),3)) for the hyperlink to the total I have for a PivotTable. But how do I get it to show the actual number as opposed to #Reps!$C$6489 in the hyperlinked cell? Any help would be great.
Finding The Address Of A Cell
I've got a spreadsheet where column A has dates and time and column C has over 8000 rows of numbers.
I'm looking to pull the date and time from column A associated with a value in column C...
how do i do a "lookup" in this case?
Find A Cell Address
I have the following macro written:
Sub GT()Dim cell As rangeDim BeforeNull As StringDim FirstNull As StringDim InitialData As StringDim B As VariantFor Each cell In range("A1:A8")Alpha: InitialData = cell FirstNull = InStr(1, InitialData, " ", vbTextCompare) If FirstNull = 1 Then InitialData = Right(InitialData, Len(InitialData) - 1) cell = InitialData GoTo Alpha End If If FirstNull "" And FirstNull "0" Then BeforeNull = Trim(Left(InitialData, FirstNull - 1)) If FirstNull = "" Or FirstNull = "0" Then BeforeNull = InitialDatacell = BeforeNullNextEnd Sub
Now after the final Next, I need the macro to select the last cell changed. Is there a way to do this?
VBA: How Can I Use Relative Cell Address
way I can use relative cell address in VBA? For example, in the following table:
value item 1 apple item 2 peach item 3 mango
Instead of use
Range("B4").Value = "mango"
to insert mango to cell B4, I can use an address that's one row under peach, or one column to the right of item 3?
Returning The Address Of A Cell
i'm trying to figure out a way that would return the address of the cell that contains the highest/lowest value of a range i.e. =cell("address",min(g3:g6)).
if the lowest value was in cell g4, i'd want the output from above formula to be $g$4.
Cell Address Of Lookup Value
I have a range of lookup values I want to use to return the "Cell Reference" of the matching value in another vector (single column).
Is there a simple function that will do this..?
eg a variation of using VLOOKUP
Cell Address Changing
I am trying to write a line for my little project but came to a stop as I do not have enough knowledge on how to get around this.
Most likely its something very simple but I'm not an expert so hopefully someone here can put me out of my misery.
I am trying to get this to work:
Function IF(AND(sheet!A1=sheet2!A1),x,y) works fine but for what I need to do I need to get sheet2!A(1+B1) As soon as I do that it all goes funny. In B1 I have a number that determines by how many cells A1 needs to be offset but I cannot get the syntax right.
Separate Address From Cell
I have a dataset with full addreses listed in one cell. I would like to use "text to columns" to separate the data but am unable to use the text separater in the wizard. When I open the text to columns wizard the data appears to be divided with a "square" but I cannot add it as "other" for the delimeter. see the attached.
Use A Cell Value In A Address Link...
I have is a summary worksheet with two columns. One column is for Project ID number and the other is an address link to a specific cell in the worksheet corresponding to the Project ID. Perhaps the best way to explain this is by giving an example:
Project ID (Column 1)
Balance (Column 2)
As you can see the spreadsheets are named after the Project ID number. What I would like to do, if possible, is instead of typing in the name of the spreadsheet for each project in column 2 (Balance), I could somehow reference the cell value in column 1 (Project ID). Something like this:
Project ID (Column 1)
Balance (Column 2)
Select Cell Address Via VBA
I have a cell, say A1 in Sheet("temp") which has a value like this:
I need some vba code which selects this range which happens to be in a different sheet.
the only way I can think of is to split this text string to worksheet and range components but i am having issues doing this in vba.