Whaletacos
New Member
- Joined
- Aug 10, 2017
- Messages
- 13
Hello wise people of the internet.
I'm tinkering with a code in VBA. It's purpose is to look at each cell in a given range.
Part 1: Looking at the LEFT side of a string, it searches for "/56-Test1/" And it MUST be the first part of a string.
Example: "A/56-Test1/AAA" should be ignored while "/56-Test1/AAA" Should be formatted.
If the "If" condition is true, then it offsets a value, and removes the found part of the string, while leaving the rest intact.
Example: Before: "/56-Test1/AAA" Example after: "AAA" and then some offset value somewhere.
I am using the Len - to remove the found string, but is there an easier way of doing it? Ie. more secure, so I dont accidentally remove a letter too much?
Part 2: exactly the same as part 1, only this time from the RIGHT side of the same string
Example: "/56-Test1/AAAA/36-Test/"
Its part of a lot of ifs. But I've attached an example below.
A big thanks to anybody who read this I hope some internet wizard is able to help
I'm tinkering with a code in VBA. It's purpose is to look at each cell in a given range.
Part 1: Looking at the LEFT side of a string, it searches for "/56-Test1/" And it MUST be the first part of a string.
Example: "A/56-Test1/AAA" should be ignored while "/56-Test1/AAA" Should be formatted.
If the "If" condition is true, then it offsets a value, and removes the found part of the string, while leaving the rest intact.
Example: Before: "/56-Test1/AAA" Example after: "AAA" and then some offset value somewhere.
I am using the Len - to remove the found string, but is there an easier way of doing it? Ie. more secure, so I dont accidentally remove a letter too much?
Part 2: exactly the same as part 1, only this time from the RIGHT side of the same string
Example: "/56-Test1/AAAA/36-Test/"
Its part of a lot of ifs. But I've attached an example below.
Code:
'Part 1
For Each rngSequence In rngSequence.Cells
If Left(rngSequence, Len(rngSequence) + 8) Like "/56-Test1/*" Then
rngSequence.Offset(0, 4).Value = "5-TestOffset1"
rngSequence = Right(rngSequence, Len(rngSequence) - 10)
ElseIf Left(rngSequence, Len(rngSequence) + 9) Like "/56-Test2/*" Then
rngSequence.Offset(0, 4).Value = "5-TestOffset2"
rngSequence = Right(rngSequence, Len(rngSequence) - 10)
'Stuff happens
'Part 2
For Each rngSequence In rngSequence.Cells
If rngSequence Like "*/36-Test1/" Then
rngSequence.Offset(0, 5).Value = "3-TetsOffset1"
rngSequence = Left(rngSequence, Len(rngSequence) - 9)
A big thanks to anybody who read this I hope some internet wizard is able to help