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
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi,

How do you know it is not recognising the text? What exactly is in the cell, is it text or a formula?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,397
Messages
6,119,273
Members
448,883
Latest member
fyfe54

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