Excel named range formula, for cell sequence - excel

I'm trying to set up a sheet that will input data in a specific cell order. Basically I need the first enter to go to the next column, and then the second enter to go to the previous column but one row down.
I linked a picture to elaborate. I thought it would be possible with just defining a named range and selecting each cell individually, but I need for this to work for 500+ rows.
It's my understanding you can use a formula to define a named range, but I'm having difficulty figuring out how to do that.
edit:
More elaboration on the input method. In this case I can only use the enter key due to the input device. This sheet also has to be shared with people, so setup instructions are not ideal.

Based on the question as it stands (and without further qualification), the following code will do what you want:
Option Explicit
Private Sub Worksheet_Change(ByVal rgTarget As Range)
With rgTarget
Select Case .Column
Case 1: .Offset(0, 1).Select
Case 2: .Offset(1, -1).Select
End Select
End With
End Sub
The above goes into the VB of the Sheet where the data entry will occur.
If you don't know what that means, let me know and I'll provide details on how to implement.

Excel recognises data entry patterns when data is entered manually.
enter something into A1 and press Tab to confirm and go to B1
enter something into B1 and press Enter.
now the active cell is A2
enter into A2 and press Tab to go to B2
enter into B2 and press Enter to go to A3
etc.
No need to set up anything special or create named ranges for that.

Related

How to have excel automatically replace one word with another word?

I'm having trouble finding my answer for this elsewhere. I need to be able to type in a code (ex. CK) and have the cell show "Checking Account" when I press enter. Or SV for Savings Account, RI for Roth IRA, etc. Here is what I have tried:
Conditional Formatting>New Rule>Use Formula> =$C$25="CK"
Then the format I input was Number>Custom> "Checking Account"
No matter what I do, it stays "CK." I'm having a hard time figuring this out. Any suggestions are appreciated. Thanks!
=if(A1=“CK”,”Checking Account”)
Replace A1 with the cell range you want CK to be replaced with Checking Account.
If it’s a range input like A1:A5 or A1:E1
Easiest I could come up with as a suggestion.
What you are trying to do, is impossible with an Excel formula: an Excel formula is present in a cell and calculates the value, based mostly from information from another cell.
You are looking for a macro, and I would advise you to check for the Worksheet_Change event, something like:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value = "CK" Then
Target.Value = "Checking Account"
End If
End Sub

Is there a way to add a cell value to a running total based on a neighboring cell value?

I'm creating a workbook to replace a company step challenge that is no longer available to us. The goal is to track steps in as real-time as possible (users will select their name from a drop-down in Cell E2 and input their steps into Cell F2). The drop-down is based on Column A using Data Validation and in Column B is their running total of steps. I would like to have a Control Button in place in Column G that takes the number of step inputted by the user and adds to the current steps for that same user in Column B.
So far, I have Data Validation running fine without issue and I have mock users in Column A and their steps in Column B. I assume the logic behind the coding would need to be Selecting the value in Cell E2 and locating that value in Column A. Once the code has a value of true, move over 1 cell to the right, add value in Cell F2 to that current selected cell value, and then delete value from Cell F2.
I attempted to start off with a range.find and I'm under the impression that is incorrect because I keep receiving errors. I then took to already posted questions to find someone with a similar issue but spent an hour just trying to create a patchwork code that didn't work in the end.
Any and all suggestions or links to forums/posts I wasn't able to locate myself would be greatly appreciated. I'm going to continue to search but as a newbie, some items I am finding are well above my skill/comprehension level.
EDIT:
So I've changed my approach based on comments. I now have a list of names spread over columns J2:S2 (this will grow as people sign-up). What I'm now attempting to do is write code that will find the person's name in the column based on cell value E2, then paste the steps they have inputted into cell F2 to the next blank row of that column. I put together another attempt at code but there is something wrong that I cannot figure out (See below). I will then just make a pivot based off of the data that will sit off the the left in Columns A:C.
With the below code I do not get any errors, nothing happens other than the clear contents. Sorry for the time before replying to comments, I wanted to attempt to do this on my own before coming back with an edit. I think there is something going on with me not specifying a cell value more clearly or I am misusing the rng.value as a way to paste rather than just check for a value.
I'm a greenhorn for sure with VBA so I'm learning rules as I go.
Sub Attempt_3()
Dim rng As Range
Set rng = sheets("Sheet1").Range("J2:S2").End(xlDown)
For Each Row In rng
If rng.Value = "E2" Then
rng.Value = rng.Offset(1, 0).Value = "F2"
End If
Next Row
Range("F2").Select
Selection.ClearContents
End Sub

reference a cell but keep formatting of text from source cell

I have a cell with some text in it.
Say cell A1.
This text is formatted in a certain way - First few words are bold, line breaks, varying font size, etc
When I reference this cell, say in cell B1:
=A1
In B1 I just get a long string of text that has none of the formatting that is present on A1
Is there a way to reference and keep the formatting?
I can use format painter and it will recognise the line breaks within the cell, but aspects like the partially bold writing are still not recognised.
As per my comment:
Private changing As Boolean
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Target.Address = [A1].Address Or changing Then Exit Sub
changing = True
[A1].Copy [B1]
changing = False
End Sub
The code above means that whenever any change is made to cell A1 (specifically A1 - that way the code doesn't execute every time a change is made on your sheet - doing that would slow everything down), whatever's in A1 is copied to B2
Usage
To use, simply
Right click on the name of your sheet (a tab along the bottom), and select "view code"
Paste the code in
Change any cell references to the ones you want (ie replace[A1] with [A3] or [A1:A4] or [blah] (i.e. a named cell/range) depending on what you need)
Close the window. To save the workbook you'll have to save as .xlsm or .xlb if you want to keep the macro
Notes
[A1] is shorthand for ThisWorkbook.ActiveSheet.Range ("A1"). Typically I would advise against using it as ActiveSheet means that if the code ran on any sheet in ThisWorkbook, it would copy and paste over the A1 and B1 of that sheet, whereas you probably only want the specific cells on a specific sheet.
However in this case, the code only applies to 1 sheet so that's not a problem.
All the changing stuff is necessary because copy/paste triggers a change event; i.e. the macro triggers itself over and over until Excel stops it - not ideal! The changing variable which I declare simply acts as a signal to stop the program executing itself.

Dynamically update a single cell with contents from a fixed column reference, but from the current, active row

I am trying to have a certain header cell in excel dynamically update its contents depend on which row I am currently using, but with an address that has a fixed column. So the column reference for the header's contents will always be the same, however, I would like to have the row address change depending on the cell I am editing (i.e. the active cell).
A B
1 (dynamic header cell)
2 John likes to eat apples
3 Mary never smokes
4 Peter tries too hard to be cool
5 David loves madonna
So, If I click on cell A2 ("John"), I want the header cell (A1) to update with the contents of B2 ("likes to eat apples"), and similarly if I click on cell A4 ("Peter"), I want the same header cell (A1) to update with the contents of B4 ("tries too hard to be cool").
I have done some research, and I think perhaps I might use some combination of the cell function or the indirect function, but I cannot manage to get this to work. I would prefer to use a simple formula, but if I need to do VBA, that is fine.
(If you suggest VBA, please include the whole function, because I don't know the language).
Can anyone help?
As Scott Craner suggests, you'll need the "Worksheet_SelectionChange" event in VBA. Since you indicate not being familiar with VBA, I'll talk you through it. First, open the VBA editor by entering Alt+F11. In the VBA editor, enter Ctrl+R to open or jump to the project explorer (it's usually a pane on the left side of the window) and double-click the name of the sheet where you want your function. Now enter the following code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not(Intersect(ActiveCell, Range("A:A")) Is Nothing) Then
Cells(1, 1).Value = Cells(Selection.Row, 2)
End If
End Sub
The first line tells VBA it should execute the code whenever the selection changes. The second line checks if your selection is in column A. The third line actually does the trick: it takes the value from the second column of the selected row and puts this value in A1.

Is there a way to automatically fill cells in a row when it is added in Excel

I don't really know much about excel especially VBA. But i need to write something(macro for ex.) that does the following:
if someone inserts a row and fills the first 4 cells of it, it needs to sort the rows (i have a macro for sorting called "sortingmacro") and then it needs to fill cells 7 and 8 by copying the cells above them.
for example if i insert a row to 4th line and fill A4,B4,C4 and D4 it needs to copy G3 to G4 and H3 to H4. (after sorting of course)
any help is appreciated.
edit:
i have formulas in the cells that are to be copied. the formulas for the first row(the top one according to sorting) is a different one and all the others are the same.
You can find out if a cell has been changed with the Worksheet_Change-Event.
Private Sub Worksheet_Change(ByVal Target As Range)
Debug.Print Target.Address
End Sub
Output (something like this):
$A$14
$B$17
$C$13
$C$21
$C$16
So if a matching cell is changed, look for the other 3 in the row and start your macro.
So put a button on the page, then go to the code for it (the click event). In that, use your sortingmacro to sort all the rows. Then you just do something simple like:
Rows(4).Cells(1,7).Formula = Rows(3).Cells(1,7).Formula
Rows(4).Cells(1,8).Formula = Rows(3).Cells(1,8).Formula
Of course instead of hardcoding 4 in there, you'd have a variable for the row (make sure and determine it after sorting).

Resources