Move cursor to specific cell from a specific cell

J

JSnow

I hope I can explain myself clearly enough to explain what I want to
accomplish. I'm using columns B through G and sometimes H. What I'd like to
have happen is if I hit enter after typing something in column H then the
cursor will go to the cell in column C of the same row (because it will be
blank).

Here's what it will look like:
Col B Col C Col D Col E Col F Col G Col H
EXAMPLE (blank) Clare 9/10 0607 018 see Clare co.

So after i type in Col H "see Clare Co." and hit enter, the cursor moves to
Col C in ths same row. I will then link the date from Clare Co. to that cell.

You vba-ers have been kick butt so far. Let's see what you got.
 
G

Gary''s Student

Put this isn the worksheet code area:

Private Sub Worksheet_Change(ByVal Target As Range)
Set h = Range("H:H")
If Intersect(Target, h) Is Nothing Then Exit Sub
Cells(Target.Row, "C").Select
End Sub


Because it is worksheet code, it is very easy to install and use:

1. right-click the tab name near the bottom of the window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you save the workbook, the macro will be saved with it.

To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm
 
J

JSnow

Gary's Student, the sheet the opened when I clicked on "view code" already
had a Private Sub Worksheet_Change(ByVal Target As Range) formula in it. I
included the set h = Range("H:H") through Cells(Target.Row... but it didn't
work.

Here's the coding already in that sheet:
Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
On Error GoTo Whoops
If Target.Count = 1 Then
If Target.Column = 2 Then 'this number picks the column: 1 is
column A, 2 is column B etc
If Target.Row > 1 Then 'ignore row 1 which is probably a header
Target.Value = UCase(Target.Value)
End If
End If
If Target.Column = 4 Then 'this number picks the column: 1 is
column A, 2 is column B etc
If Target.Row > 1 Then 'ignore row 1 which is probably a header
Target.Value = StrConv(Target.Value, vbProperCase)
End If
End If
End If

Whoops:
Application.EnableEvents = True

Set t = Target
Set b = Range("C:F")
If Intersect(t, b) Is Nothing Then Exit Sub
If t.NumberFormat = "General" Then Exit Sub
Dim s As String
s = t.Value
If Left(s, 1) <> "=" Then Exit Sub
Application.EnableEvents = False
t.NumberFormat = "General"
t.Formula = s
Application.EnableEvents = True

End Sub

I actually have 26 sheets (1 for each letter of the alphabet). Could I use
your code in the ThisWorkbook page?
 
G

Gary''s Student

If you already have a Worksheet_Change sub, keep it. Remove my sub.

In YOUR sub include the following lines directly after the Private line:

Set h = Range("H:H")
If Intersect(Target, h) Is Nothing Then
Else
Cells(Target.Row, "C").Select
Exit Sub
End If

This leaves your original logic intact. We are just adding a check that if
something is entered in col H, a jump is made back to column C.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top