I have a column of values D1:D200. Using this =CELL("address",INDEX(D1:D200,MATCH(MAX(D1:D200),D1:D200,0))) it displays the cell with the largest value in. I have been trying to using VBA to select the 10 cells above and below the displayed CELL reference and so far I have failed. The largest value will always be somewhere in the centre of the column of values (between D50 and D150). I am looking to chart the trends leading up to and passed the largest value. I have been trying Range and Cells with no success
I've normally just dynamically selected a range using the xldown feature but because this row contains formula it goes always down to the bottom of the formula instead of the last cell which isn't blank.
How would i go about generating this dynamic range that stops at the first cell that contains no value (but has a formula)? Perhaps a do while loop which looped down until it hit the first blank and then assigned the cells it had looped through as the range?
Question 1) Is there a way that whenever I select Cell B39 that it will copy cells B39:V39 ? From there I can manually paste that selection to where I need to.
If this is possible, it would save the effort of having to select B39:V39 manually and clicking CTRL-C. I am gathering data and the copying and pasting is killing me.
Question 2) Is it possible that when I click on Cell A9 that it can paste any data that I just copied from another worksheet to cells A9:D29? The size of the selection that I would copy is the same size as A9:D29 (4 columns & 29 rows).
I have searched for a solution, but I am not having much luck since I am anaware of the proper terminology for these types of actions.
I need a cell to display the (text) content of 1 of 25 cells. example: I have text content in all cells ranging A1:A25. I want cell B1 to display the content of 1 of these at random. is there a function for this or do I need to use a macro?
I have a form that loads and depending on the word selected in the drop down the following code loops through cells Q2:AC2 until it finds the word in one of those cells (the word will always be in one of the cells)
Code: For Each c In Range("Q2:AC2").Cells If c = period Then c.Select
The active cell it finds will always change, i know I need something to code the active cell back but I don't know what it should be.
I would like to select a range of cells relative to the current cell and move them to the right two cells. Basically, if I were in cell A1 I want to be able to have a macro select A1 - A8 and move them over by two cells leaving A1 and A2 blank.
I need a formula to sum all E3 cells starting from sheet "Joe" to the last sheet i have, without being obliged to modify the formula for each new sheet i create and which by default is created in the end. something like: =sum(Joe:my last sheet created!E3)
Also,do protected cells in some of the sheets affect this formula calculation?
I am using this code to hide or unhide rows of text on another sheet:
VB: Sub ProcessSheet1ChangeOnCellJ7(ByVal Target As Range)
Dim sAddress As String Dim sValue As String
'Get the address of the cell that changed without '$' signs sAddress = Target.Address(False, False)
When the "Not Pursuing" list box option is selected (in cell "J7" or "J8" in Sheet 1) I need to add (or over-write) "Not Pursuing" to the range of cells in column "B" (in the "Tasks" sheet), but only for that particular Goal, meaning a limited range of cells in column "B". If the "Pursuing - Show All Tasks" option is selected for a Goal then these same cells need to be blank so that the appropriate person can enter their name into the cell.
The purpose for adding "Not Pursuing" automatically to these yellow highlighted cells is that it will facilitate filtering of tasks by individual in the "Tasks" sheet..
Again I have tried several times to upload a sample file and am unable to, which I know makes it more difficult to solve. (Is there some common mistake people make? I know it's an allowed format and is very small in file size....)
Code solution can be entered directly beneath:
VB: If Target.Value = "Not Pursuing" Then ActiveWorkbook.Sheets("Tasks").Rows("29:29").EntireRow.Hidden = False ActiveWorkbook.Sheets("Tasks").Rows("30:48").EntireRow.Hidden = True
VB: Sub autofill() Range("A1").Select Selection.autofill Destination:=Range("A1:A1048576 "), Type:=xlFillDefault End Sub
but i need to select first cell in every 20th column and then execute autofill till the last row that excel provides. I can only do this manually but I have for now 125 columns to fill or to write some monstrous code. Unfortunately I do not have the knowledge to do this in a smart way and I guess there is an elegant way to solve this problem.
Dim MyData As Range Dim MyResult As Range Set MyData = Range("E1:E1000000") Set MyData2 = Range("F1:F1000000") Set MyResult = Range("J4") MyResult.Select Selection.Formula = "=COUNTIFS(" & MyData.Address & ",""=Kim""," & MyData2.Address & ",""=done"" )"
Is there any way I can change the code so that it automatically finds the last cell as Im using Range("E1:E1000000") and Range("F1:F1000000") because there will not be more than 1000000 entries.
I have 12 named ranges on a sheet, ArrM1 thru ArrM12. Each named range is same size, 6 Rows by 7 columns.
Q. If user selects a cell on sheet that is in one of these ranges, what is code to return name of range? e.g. ArrM1 is cells c10:i15, user selects cell d12; I would like vba to return the name of the range "ArrM1".
Reason, I have the code below so if user selects cell in ArrM1 code is executed, but rather than reproduce code 12 times for each range I thought I could first see where user selects and then change variable for vrange, Set vrange = wksYearlyCalendar.Range("ArrM1") to Set vrange = wksYearlyCalendar.Range("ArrM" & x)
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim CalDaySel As String, CalDateSel As String Dim vrange As Range Dim cell As Range
I have a short macro to remove highlighting from certain fields when data is entered. Here is the full
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(ActiveCell, Range("j18:j500")) Is Nothing Then Sheets("Internal Transfers").Unprotect Password:="" With Target.Interior .ColorIndex = 0 .Pattern = xlSolid End With Sheets("Internal Transfers").Protect Password:="" End If
The highlighting only goes away if you hit the Enter key after entering data in the cell. If you use the tab key after entering data, or use the mouse to select a new cell, the highlighting change doesn't occur. I have a feeling this might simply be related to the way I'm invoking this event. I've not worked with the worksheet_change event before, but I've read through various explanations and descriptions of this event and it isn't clear to me what I need to do.
I'm looking for the least amount of code to apply a border around every cell in a selected range. The standard With Selection approach is to go through six times for the sides, top, bottom, and insides, which results in a lot of code.
I attempted a single code line approach (Selection.Borders.LineStyle = xlContinuous), but I cannot seem to influence the color or thickness of the line. I'm not looking for fancy here...standard xlThin in black color is all I need.
The goal of that formula was to return a Date/Time stamp that is fixed and doesn't change over time. The formula is intended to run in which ever cell that I select to enter it into. I named the formula:
What I am trying to do is create a macro that will run the formula using a hot key function. I want to be able to select a cell and hit CTRL D and have that above formula run in that cell. I have multiple sheets in my workbook and I need the macro to be able to run on any sheet in my workbook. Below is what I have:
Sub DateStamp() ' ' DateStamp Macro
I was trying to apply the macro to only a certain range of cells on any given sheet.
I am looking to run two separate macros. I have a project plan and I am looking to be able to select a button whereby on-click, a new row is created within a selected cell. However if the cell clicked is outside of a pre-determined range, then the task is automatically entered at the bottom of the plan. I would like for the copied row to go ABOVE the selected cell and have all of the same formatting as the row below (not the top - as is default in Excel).
The second is going to be very similar but will copy a task category (like a header item) and the first task (row) found below. It will also be copied from below and be inserted above the selected cell.Both macros will clear certain cells, whilst maintaining the contents of others, with formula contained. I.E. Columns C,D,E,H,I,J will be cleared.
The rows will differ depending on the Active Cell that's selected and I don't know how to specify this. The range I want to copy is from Column B to DA on the worksheet ("Staff") which I want to paste to another worksheet ("Leavers"). This is as far as I got
'FindRemove = lstRemove.Value 'If FindRemove = "" Then End
' Goes to the start of the Data column 'Sheets("Staff").Select 'Range("B4").Select
' Tests current cell against FindRemove 'Do 'If ActiveCell.Value = FindRemove Then 'Call CopyPerson 'Exit Sub 'Else: ActiveCell.Offset(1, 0).Select 'End If 'Loop Until ActiveCell.Value = "" 'End Sub
I am carrying out some sensitivity testing on a model, and would like to greatly increase the speed of the process by being able to call in from a user defined cell a named range, which is then pasted to the right of the cell.
The attached file steps through the process I have in mind.
I am using the following Selection_Change Event to show a UserForm when a cell in 1 of 31 named ranges is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Count > 1 Then Exit Sub Dim i As Long
For i = 1 To 31 If Not Intersect(Target, Range("StatPost" & i)) Is Nothing And Target.Value = "" Then If Target.Offset(0, -8).Value = "" Or Target.Offset(0, -7).Value = "" Or Target.Offset(0, -6).Value = "" Or Target.Offset(0, -5).Value = "" Or Target.Offset(0, -3).Value = "" Or Target.Offset(0, -2).Value = "" Or Target.Offset(0, -1).Value = "" Then....................