ActiveCell.Offset not recognising text

bradyj7

Board Regular
Joined
Mar 2, 2011
Messages
106
Hi All,

I'm trying to write some code to loop through some data and to do something if one condition (two things must be true) is satisfied or a separate condition is. The code is working so far as in if the first condition is meet it performs the action but it not working for the other condition. Here is the code
Code:
    i = 1

    Range("j2").Select

   'do loop to check 3 things, conditions are 1 and 2, or 3:
   '1. acceleration is negative
   '2. speed is zero
   '3. The text 'Journey End Event' is found in the cell
    
    
    
    Do

        If (ActiveCell.Offset(0, -3) < 0 And ActiveCell.Offset(0, -6) = 0) Or ActiveCell.Offset(0, -5) = "Journey End Event" Then

        ActiveCell.Value = i
        i = i + 1


        End If

    ActiveCell.Offset(1, 0).Select

    Loop Until IsEmpty(ActiveCell.Offset(0, -1))
The code is not recognising the text 'Journey End Event' in the cell. I've tried this code also but it not working either.
Code:
ActiveCell.Offset(0, -5).text = "Journey End Event"

Its a simple problem but cant seem to figure it out. Any ideas?

John
 

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

JamesW

Well-known Member
Joined
Oct 30, 2009
Messages
1,197
Hi,

How do you know it is not recognising the text? What exactly is in the cell, is it text or a formula?
 

MrKowz

Well-known Member
Joined
Jun 30, 2008
Messages
6,653
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Try using .Value instead of .Text.

Also, try out this code and see if it does what you need:

Code:
Public Sub bradyj()
Dim i   As Long, _
    LR  As Long
 
LR = Range("J" & Rows.Count).End(xlUp).Row
   'do loop to check 3 things, conditions are 1 and 2, or 3:
   '1. acceleration is negative
   '2. speed is zero
   '3. The text 'Journey End Event' is found in the cell
   
For i = 2 To LR
    If (Range("G" & i).Value < 0 And Range("D" & i).Value = 0) Or Range("E" & i).Value = "Journey End Event" Then
        Range("J" & i).Value = i
    End If
Next i
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,222
Messages
5,594,904
Members
413,952
Latest member
JGer

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
Top