• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Left Offset Code

Dokat

Member
Hi,

I have a below code i am trying to modify.

I have a value in cell P11. if the value in cell P11 starts with "L", I'd like to put "L13W and the last 8 digits of cell P11 in Q11. Can you please help

Code:
Sub RightFunction()
Dim c As Range
For Each c In ThisWorkbook.Sheets("Data").Range("P11")
  If Left(c.Offset(0, 0), 1) = "" Then
      c.Offset(0, 1).Value = "L13W " & Right(c.Offset(0, 0), 8)
   ElseIf Left(c.Offset(0, -1), 1) = "B" Then
      c.Value = "YTD"
  End If
Next
End Sub

Modified to below code and its working now.

Code:
Sub RightFunction()
Dim c As Range
For Each c In ThisWorkbook.Sheets("Data").Range("P11")
  If Left(c.Value, 1) = "L" Then
      c.Offset(0, 1).Value = "L13W " & Right(c.Value, 8)
   ElseIf Left(c.Offset(0, -1), 1) = "B" Then
      c.Value = "YTD"
  End If
Next
End Sub
 
Last edited:
Back
Top