Trying to hide text in an excel cell - excel

I am looking at running test on survey results. For the column headers for each question they are IMP1, IMP2, etc. What I want to be able to do is place the question in this cell so that when you click on the header you can see the question but from the overview of the file all the user can see is IMP1.
Not sure if that wording makes sense but basically I want the text in the formula section when you click on a cell. When the cell isn't selected it should just show IMP1.

This is specifically for the single cell A1, but can be expanded to process all the cells in column A. First enter this in the cell:
IMP1What is the meaning of life ??
and then place the following Event Macro in the worksheet code area:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim A1 As Range
Set A1 = Range("A1")
l = Len(A1.Text)
If Intersect(A1, ActiveCell) Is Nothing Then
A1.Characters(Start:=1, Length:=l).Font.ColorIndex = 1
A1.Characters(Start:=5, Length:=l).Font.ColorIndex = 2
Else
A1.Characters(Start:=1, Length:=l).Font.ColorIndex = 1
A1.Characters(Start:=1, Length:=4).Font.ColorIndex = 2
End If
End Sub
If you click on A1, you will see:
and if you click off the cell, you will see:
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!

Besides using Comments you could use a VBA subroutine to do this based on the worksheet's SelectionChange event. In your VBE, double click the worksheet where this event is taking place in the VBAProject pane. In that code window place the following:
'Global Variable to hold the last column A cell that was clicked into
Private lastClicked As Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Did we click out of a column A cell?
If Not lastClicked Is Nothing Then
If Target <> lastClicked Then
'Copy the holder value from column C back to Column A
lastClicked.Value = lastClicked.Offset(, 2).Value
Set lastClicked = Nothing
End If
End If
'Detect a click into column A
If Target.Column = 1 Then
'Update the global "lastClicked" variable
Set lastClicked = Target
'Move the holder text to column C
Target.Offset(, 2) = Target.Value
'Move the question text from column B to target
Target.Value = Target.Offset(, 1).Value
End If
End Sub
This set up is assuming that your questions (the holder text like IMP1) is in Column A of the worksheet, and that you would have the entire question hidden (I assume) in Column B. Also that Column C would be empty so that we could temporarily hold the holder text (although you could stuff that into it's own global variable as well).

Related

How to jump to a specific cell based on the list selection

I have created a drop-down list in cell R5 containing names, lets call them Name1 Name2 Name3. I'd like when the user selects a certain name the sheet will scroll down to a specific row. For instance, if Name 1 is selected I'd like it to go to row 2, if Name2 is selected row 10, and Name3 row 18. The list is on the same worksheet as the data I'm wanting to scroll to. Is there some code I can use to do this?
You would need to use Sheet Events to handle this. Something like this:
In your Worksheet Module of the worksheet that has your input range, put this code
Private Sub Worksheet_Change(ByVal Target As Range)
Dim InputRange As Excel.Range
Set InputRange = Me.Range("R5")
'// Check if the change is happening in your dropdown cell
If Not Intersect(Target, InputRange) Is Nothing Then
Select Case InputRange.Value
Case "Name1"
Application.ActiveWindow.ScrollRow = 2
Case "Name2"
Application.ActiveWindow.ScrollRow = 10
Case "Name3"
Application.ActiveWindow.ScrollRow = 18
Case Else
'//...
End Select
End If
End Sub
Edit:
If you're having trouble getting this to work. Try adding a breakpoint by clicking in the area to the left of the code. A breakpoint will halt execution when the flow of code reaches that point. This is one way to figure out if Excel is even TRYING to run this block of code.
Debugging Excel Code
Say we put a little jump table in columns S and T like:
The row numbers are in column T. We put the drop-down in R5 and the following code in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim R5 As Range, v As String, r As Range
Set R5 = Range("R5")
If Intersect(Target, R5) Is Nothing Then Exit Sub
v = R5.Value
Set r = Range("S:S").Find(what:=v, After:=Range("S1"))
Application.Goto Range("A" & r.Offset(0, 1).Value)
End Sub
Whenever the user picks a new name in cell R5, the code will jump to the row listed in column T.
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!
Right click on the cell. At bottom of the popped up window you find "Hyperlink". Click it. Another window opens. There select the sheet and enter the cell number where you want to go. That's all. In this cell the address given under hyperlink appears. If you give a name to it that name appears. Thereafter whenever you click on this cell/name in this sheet you go to the cell in the sheet specified under "Hyperlink". You can enter data in the new place. But you won't be able to come back to this cell on pressing enter. When you press "Enter" in the new place you go to the next cell in that sheet as usual. I used another hyperlink to come back. It is working for me. I Hope this is a facility provided by excel for jumping easily to a new location based on the hyperlink. Hope there won't be any cascading effect. I hope this is exactly what you wanted.
Press TAB on your keyboard. It might work. Just try it.

In excel how do i make cells in a column/row clickable?

In excel how do i make cells in a column/row clickable?
I have a data grid and want to be able to click on a cell in column N and have that data in that cell appear in another cell.
I also want to be able to click on a cell in row 3 and have that data appear in a second cell.
(Table begins at column N and row 3)
Here is a method for double click
Enter the following event macro in the worksheet code area:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim Reg As Range, B2 As Range
Set Reg = Union(Cells(1, 1).EntireRow, Cells(1, 1).EntireColumn).Cells
Set B2 = Range("B2")
If Intersect(Target, Reg) Is Nothing Then Exit Sub
Cancel = True
B2.Value = Target.Value
End Sub
If you double click on a cell in column A or row#1, its value will appear in cell B2
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!

Function referring to the last entered cell in a column

I want a function that refers to the last entered cell in a particular column. For example, consider column A and the entries are as follows.
1st entry in column is in cell A1,
2nd in A2, 3rd in A5, 4th in A8, 5th in A7.
Now i want a function that refers to the cell A7.
With data in column A use
=LOOKUP(2,1/(A:A>0),A:A)
For example:
Will display Albert
Here is the macro approach. The macro monitors changes made to column A and records the last value in cell B1
Insert this event macro in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range, B As Range
Set A = Range("A:A")
Set B = Range("B1")
If Intersect(A, Target) Is Nothing Then Exit Sub
Application.EnableEvents = False
B = Target.Value
Application.EnableEvents = True
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!

Create A popup InputBox from a cell and right the value to the next one

Hello this is my first question here and I'm new in VBA programming. I'm looking for a VBA code that would allows me when I select a cell on a range of cells to pop-up an input box to put some values.
For example when I select a cell from column B an input box pops up, requiring a value that goes to next cell in column C. That's because in the column B I have stored a formula (& the cell is locked) and I would not like to be deleted or changed by the user although I need his Input Value to be calculated by the formula, so I choose to store this value in a hidden cell next to it and make the reference into my formula.
How is this possible with VBA?
Thanks in advance,
Harris
This technique uses double click rather than single click. Your protection must allow the user to double click cells in column B
Enter the following Event macro in the worksheet code area:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim t As Range, B As Range
Set t = Target
Set B = Range("B:B")
If Intersect(t, B) Is Nothing Then Exit Sub
Cancel = True
t.Offset(0, 1).Value = Application.InputBox(Prompt:="Enter data value", Type:=1)
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!
I would suggest using the following Code:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("B:B")) Is Nothing Then
Cells(Target.Row, Target.Column + 1).Value = Application.InputBox("Insert your value please")
End If
End If
End Sub
This pops an inputbox up if you select any cell in column B and puts the value to the Cell in C. You have to put the Code directly into the particular Sheet in the VBA Window.

Make an excel cell mandatory, based on value of other 2 cells

So.. I've an excel where 2 consecutive cells can be marked with the same value (mostly Text), based on this 2 cells the value of the 3rd cell should be filled mandatorily by the user.
The range of cells can be different as I need to use the same snippet cross many excels.
Any help would be sincerely appreciated.
Many thanks! :)
There's more then one way to skin a cat, but probably the easiest way to do it would be to include a vba sub which (on some trigger, like submitting) checks the value of cell 1 and 2 and IF that value is whatever you want to trigger on... if cell 3 is blank prompt the user to fill in box three.
IF Range("A1").Value == "Trigger" And Range("A2").Value == "Trigger" And Range("A3") == "" Then msgBox("You must fill in cell A3")
If you add a break statement like End Sub, the sheet can't continue until that cell is filled.
This is an example for A1, B1, C1 enter the following event macro in the worksheet code area:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim A As Range, B As Range, C As Range
Set A = Range("A1")
Set B = Range("B1")
Set C = Range("C1")
If A <> "" And B <> "" And C = "" Then
Application.EnableEvents = False
C.Select
Application.EnableEvents = True
MsgBox "please enter a value in cell C1"
End If
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!

Resources