Small tweak needed to code

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi

The following code in a worksheet_change event works, except for "jump from F to H on that same row":
VBA Code:
Dim NextRow As Long
lr = Range("A" & Rows.Count).End(xlUp).Row
If target.Column = 2 And target.Value = "OTHER" Then
    Range("A" & target.Row).Resize(, 6).Interior.Color = RGB(197, 217, 241)
    Range("I" & target.Row).Resize(, 2).Interior.Color = RGB(197, 217, 241)
    Application.EnableEvents = False
    Range("I" & target.Row).Value = "Indoor bike session, 60 mins."
    'select cell col F
    Range("F" & target.Row).Select
    Application.EnableEvents = True

 Application.EnableEvents = False
    MsgBox "Enter heart rate", vbInformation, "Indoor Bike Session Data"
   


 ' jump from F to H on that same row
If target.Address(0, 0) = Range("F" & lr).Address(0, 0) Then
    Range("H" & target.Row).Select
    Application.EnableEvents = True
End If
End If

Column G contains a formula that is dependent on the Col F value input and I think that's what's stopping the final part from running, but I don't know how to fix this.

Help appreciated.

Thank you!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Resolved
VBA Code:
Dim NextRow As Long

lr = Range("A" & Rows.Count).End(xlUp).Row

If target.Column = 2 And target.Value = "OTHER" Then
    Application.EnableEvents = False
Range("A" & target.Row).Resize(, 6).Interior.Color = RGB(197, 217, 241)
Range("I" & target.Row).Resize(, 2).Interior.Color = RGB(197, 217, 241)
    Range("I" & target.Row).Value = "Indoor bike session, 60 mins."
    Range("F" & target.Row).Select 'move to this cell to start inputting data

    MsgBox "Enter Heart Rate", vbInformation, "Indoor Bike Session Data"
End If
Application.EnableEvents = True
' jump from F to H on the same row
If target.Address(0, 0) = Range("F" & lr).Address(0, 0) Then
    Range("H" & lr).Select
End If
 
Upvote 0
Solution
Couldn't you just go to the cell..
VBA Code:
Sub Worksheet_change(ByVal target As Range)
Dim NextRow As Long
lr = Range("A" & Rows.Count).End(xlUp).Row
If target.Column = 2 And target.Value = "OTHER" Then
    Application.EnableEvents = False
Range("A" & target.Row).Resize(, 6).Interior.Color = RGB(197, 217, 241)
Range("I" & target.Row).Resize(, 2).Interior.Color = RGB(197, 217, 241)
    Range("I" & target.Row).Value = "Indoor bike session, 60 mins."
    Range("F" & target.Row).Select 'move to this cell to start inputting data
    MsgBox "Enter Heart Rate", vbInformation, "Indoor Bike Session Data"
End If
Application.EnableEvents = True
    Range("H" & lr).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,838
Messages
6,121,885
Members
449,057
Latest member
Moo4247

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top