Page 1
Page 1
Started By
Message

Excel guru's needed badly...

Posted on 10/25/15 at 7:39 pm
Posted by yankeeundercover
Buffalo, NY
Member since Jan 2010
36373 posts
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.
This post was edited on 10/25/15 at 7:45 pm
Posted by yankeeundercover
Buffalo, NY
Member since Jan 2010
36373 posts
Posted on 10/25/15 at 8:19 pm to
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
This post was edited on 10/25/15 at 8:20 pm
Posted by LSUtigerME
Walker, LA
Member since Oct 2012
3789 posts
Posted on 10/25/15 at 10:21 pm to
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.
This post was edited on 10/25/15 at 10:23 pm
Posted by yankeeundercover
Buffalo, NY
Member since Jan 2010
36373 posts
Posted on 10/26/15 at 12:00 am to
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...)
Posted by AthensTiger
Athens, GA
Member since Jul 2008
2977 posts
Posted on 10/27/15 at 7:38 am to
try this in your proc

Set LastCell = Target

Target.Offset(0, 2).Value = InputBox("Enter something")
Posted by yankeeundercover
Buffalo, NY
Member since Jan 2010
36373 posts
Posted on 10/27/15 at 11:32 pm to
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?
Posted by AthensTiger
Athens, GA
Member since Jul 2008
2977 posts
Posted on 10/28/15 at 5:19 am to
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 by Dan Bilzerian
..on my yacht or jet.
Member since Dec 2014
1864 posts
Posted on 10/28/15 at 8:59 am to
quote:

Any ideas?


Start drinking.

Heavily.
Posted by lynxcat
Member since Jan 2008
24125 posts
Posted on 10/28/15 at 10:00 am to
There has to be an easier way than writing a complex macro.
first pageprev pagePage 1 of 1Next pagelast page
refresh

Back to top
logoFollow TigerDroppings for LSU Football News
Follow us on Twitter, Facebook and Instagram to get the latest updates on LSU Football and Recruiting.

FacebookTwitterInstagram