I need to know what is wrong with this macro: Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Sub AddNew_Calr() Dim CalrDBRow As Long Dim CalrDBCol As Long If Not Intersect(Target, Range("A3:F10002")) Is Nothing Then CalrDBRow = Target.Row CalrDBCol = Target.Column With Sheet2 Sheet1.Range("B2").Value = CalrDBCol Sheet1.Range("B3").Value = CalrDBRow Sheet1.Range("F6").Select End With End If End Sub
Kevin Robertson
@Reply 4 years ago
What is it supposed to do? What problems are there?
You do have an extra End Sub
Earl BrewerOP
@Reply 4 years ago
it is suppose to look in the CallerDB for the name selected in F6. If found it should assign the values for CalrDBRow and CalrDBCol. Once completed it with change focus to Sheet1 F6.
Earl BrewerOP
@Reply 4 years ago
I get an error that it cannot open the macro and that Target is not defined. The extra End Sub for the selctonChange sub.
Kevin Robertson
@Reply 4 years ago
What is the with Sheet2 for? It doesn't appear to do anything. I thing one of the problems may be you have a sub inside another sub. Target is not defined in the sub you are calling it from.
I'm no expert in Excel VBA but try this and see if it works.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim CalrDBRow As Long
Dim CalrDBCol As Long
If Not Intersect(Target, Range("A3:F10002")) Is Nothing Then
CalrDBRow = Target.Row
CalrDBCol = Target.Column
Sheet1.Range("B2").Value = CalrDBCol
Sheet1.Range("B3").Value = CalrDBRow
Sheet1.Range("F6").Select
End If
End Sub
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Excel Forum.