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

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!

Related

Trying to hide text in an excel cell

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).

formula changing the original cell's value

It might be a strange question, but is it possible to use a formula that changes the original cell's value to the outcome of that formula?
for example: I fill in C5 "10", and I inserted a formula there that multiplies it by 5, so the value in C5 will change to "50"
of course it mustn't make a loop, multiplying every new value by 5 so the cell will soon be too small for the number. (10)*5)*5)*5)*5)*5....
only once.
I hope this is possible although I don't think so.
Cheers,
Bart.
Say we enter values in cell C5 and want to have the value automatically multiplied by 5 each time we enter a new value.
Place the following Event Macro in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim C5 As Range
Set C5 = Range("C5")
If Intersect(Target, C5) Is Nothing Then Exit Sub
Application.EnableEvents = False
C5 = 5 * C5
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!

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!

How to make excel automatically fill a value in a cell of a sheet when another corresponding cell of another sheet is filled the same value?

For example, I have cell A1 in sheet 1 and its value is "yes". If I fill in the cell A1 in sheet2 ='sheet1'!A1 then we know what is going on. However, how can I make the cell A2 in sheet2 also have "yes" when I fill in cell A2 of sheet1 without filling in cell A2 of sheet2 ='sheet1'!A2 ?
In other word, I want to make excel automatically fill a cell of sheet2 each time when I fill a value in corresponding cell of sheet1.
Enter the following event macro in the Sheet1 code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim r As Range
For Each r In Target
addy = r.Address
Sheets("Sheet2").Range(addy).Value = r.Value
Next r
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.

Resources