- My Forums
- Tiger Rant
- LSU Recruiting
- SEC Rant
- Saints Talk
- Pelicans Talk
- More Sports Board
- Fantasy Sports
- Golf Board
- Soccer Board
- O-T Lounge
- Tech Board
- Home/Garden Board
- Outdoor Board
- Health/Fitness Board
- Movie/TV Board
- Book Board
- Music Board
- Political Talk
- Money Talk
- Fark Board
- Gaming Board
- Travel Board
- Food/Drink Board
- Ticket Exchange
- TD Help Board
Customize My Forums- View All Forums
- Show Left Links
- Topic Sort Options
- Trending Topics
- Recent Topics
- Active Topics
Started By
Message
Excel guru's needed badly...
Posted on 10/25/15 at 7:39 pm
Posted on 10/25/15 at 7:39 pm
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static LastCell As Range
If Target.Cells.Count > 1 Then
Exit Sub
End If
If LastCell Is Nothing Then
Set LastCell = Target
End If
If LastCell.Address(False, False) = "F5" Then '<<< CHANGE
If LastCell.Value = vbNullString Then
Application.EnableEvents = False
LastCell.Select
MsgBox "Enter a Value!"
Application.EnableEvents = True
End If
Set LastCell = Range("F5") '<<< CHANGE
Else
Set LastCell = Target
End If
End Sub
I used this above code to build some VB into a spreadsheet I'm building... I'm not super familiar with macros or editing the VB side of things..
I'm trying to expand this code to populate with this message for each subsequent sell...
For instance, I've got Columns A, B, C, D, E, F.
If I select something from the drop down in column A, I want it to be required to put something in column C on the same row.
The code I put in seems to only work for the first cell in the column.. so I get the error if I delete the text, but no notification if I choose a value in A, and then click somewhere else.... I want it to be required to put a value in C as soon as you select a value in A.
Basically, *ANY* value in A will require entry into C... If A has a value, C cannot be left blank and an error will pop-up.
Any ideas?
TIA.
Static LastCell As Range
If Target.Cells.Count > 1 Then
Exit Sub
End If
If LastCell Is Nothing Then
Set LastCell = Target
End If
If LastCell.Address(False, False) = "F5" Then '<<< CHANGE
If LastCell.Value = vbNullString Then
Application.EnableEvents = False
LastCell.Select
MsgBox "Enter a Value!"
Application.EnableEvents = True
End If
Set LastCell = Range("F5") '<<< CHANGE
Else
Set LastCell = Target
End If
End Sub
I used this above code to build some VB into a spreadsheet I'm building... I'm not super familiar with macros or editing the VB side of things..
I'm trying to expand this code to populate with this message for each subsequent sell...
For instance, I've got Columns A, B, C, D, E, F.
If I select something from the drop down in column A, I want it to be required to put something in column C on the same row.
The code I put in seems to only work for the first cell in the column.. so I get the error if I delete the text, but no notification if I choose a value in A, and then click somewhere else.... I want it to be required to put a value in C as soon as you select a value in A.
Basically, *ANY* value in A will require entry into C... If A has a value, C cannot be left blank and an error will pop-up.
Any ideas?
TIA.
This post was edited on 10/25/15 at 7:45 pm
Posted on 10/25/15 at 8:19 pm to yankeeundercover
I was able to get it adhere to the rule, but now if you accidentally click in that column, you're locked in and HAVE to put a value...
I want it to be row-dependent when there is a value in column A...
Uhg!
New code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static LastCell As Range
If Target.Cells.Count > 1 Then
Exit Sub
End If
If LastCell Is Nothing Then
Set LastCell = Target
End If
If Not Intersect(Range("F4:F32"), LastCell) Is Nothing Then ' <<< CHANGE
If LastCell.Value = vbNullString Then
Application.EnableEvents = False
LastCell.Select
MsgBox "Enter a Value!"
Application.EnableEvents = True
End If
Set LastCell = ActiveCell '<<< CHANGE
Else
Set LastCell = Target
End If
End Sub
I want it to be row-dependent when there is a value in column A...
Uhg!
New code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static LastCell As Range
If Target.Cells.Count > 1 Then
Exit Sub
End If
If LastCell Is Nothing Then
Set LastCell = Target
End If
If Not Intersect(Range("F4:F32"), LastCell) Is Nothing Then ' <<< CHANGE
If LastCell.Value = vbNullString Then
Application.EnableEvents = False
LastCell.Select
MsgBox "Enter a Value!"
Application.EnableEvents = True
End If
Set LastCell = ActiveCell '<<< CHANGE
Else
Set LastCell = Target
End If
End Sub
This post was edited on 10/25/15 at 8:20 pm
Posted on 10/25/15 at 10:21 pm to yankeeundercover
This seems a bit complex for a simple operation.
I can take look in AM, but there's nothing in Data Validation that will do this?
In brief, you want to force the user to enter a value in Column C when they make a selection in Column A?
Is Column A a drop down? Why not simply have the macro generate an Input Box after the value is selected in Column A? This will force them to input a value that will be written to Col C. If they cancel that entry, it can clear Col A.
I can take look in AM, but there's nothing in Data Validation that will do this?
In brief, you want to force the user to enter a value in Column C when they make a selection in Column A?
Is Column A a drop down? Why not simply have the macro generate an Input Box after the value is selected in Column A? This will force them to input a value that will be written to Col C. If they cancel that entry, it can clear Col A.
This post was edited on 10/25/15 at 10:23 pm
Posted on 10/26/15 at 12:00 am to LSUtigerME
That's exactly what I want to do (I think, lol)
Hit me <--- @gmail.com if you think you have the coding...
And I know that DV should handle it, but I can't seem to get it in correctly.
(And Yes, column A is a drop down...)
Hit me <--- @gmail.com if you think you have the coding...
And I know that DV should handle it, but I can't seem to get it in correctly.
(And Yes, column A is a drop down...)
Posted on 10/27/15 at 7:38 am to yankeeundercover
try this in your proc
Set LastCell = Target
Target.Offset(0, 2).Value = InputBox("Enter something")
Set LastCell = Target
Target.Offset(0, 2).Value = InputBox("Enter something")
Posted on 10/27/15 at 11:32 pm to AthensTiger
Uhg!!! Now I can't find out how to pull up the code I put in since I've closed the .xlsm
Any advice on pulling it back up?
Any advice on pulling it back up?
Posted on 10/28/15 at 5:19 am to yankeeundercover
I don't know what version of excel you have. I think in v13 go to Developer tab>macros. You need to find macros and open(edit) the macro you built.
Posted on 10/28/15 at 8:59 am to yankeeundercover
quote:
Any ideas?
Start drinking.
Heavily.
Posted on 10/28/15 at 10:00 am to Dan Bilzerian
There has to be an easier way than writing a complex macro.
Popular
Back to top
Follow TigerDroppings for LSU Football News