Need assistance with VBA

deftincu

New Member
Joined
Jul 19, 2024
Messages
13
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Hoping someone can help with code, as I am still fairly new to VBA (with all the assistance I’ve received in previous posts, I have learned quite a bit - thank you!).

I have a drop down list in range AA:AA which contains several statuses. I have created the below code which offsets the adjacent cell in column G, concatenating “-Cancel” with the already existing value in the cell, when the status “Cancel Pending” or “Cancel” is chosen from the drop down. Under normal circumstances, pending is chosen first, followed by cancel; however, there are certain situations where only cancel will be chosen, therefore, it is imperative that either one of those two statuses will initiate the “-Cancel” in column G.

The issue I am trying to solve for is that “-Cancel” is entered each time the status changes, resulting in “-Cancel-Cancel” being added to the cell. I would like for the code to check if “-Cancel” already exists in the cell, and, if so, no value is entered. As you can see, I attempted to use <> and wild card, but it does not work (I honestly didn’t expect it to either). I am unsure of how to combine a partial match search of the value in the offset cell with what I currently have. Let me know if any additional info is needed. Thank you in advance for your assistance!

VBA Code:
Case Left(Target.Value, 6) = "Cancel"
        With Target.Offset(0, -20)
               If .Value <> "*Cancel*" Then
                   .Value = .Value & "-Cancel"
               End If
         End With
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
If it is always going to be either just Cancel or that Cancel will appended as the last addition couldn't you just check for Cancel in the last position ?

Rich (BB code):
    Case Left(Target.Value, 6) = "Cancel"
            With Target.Offset(0, -20)
                   If Right(.Value, 6) <> "Cancel" Then
                       .Value = .Value & "-Cancel"
                   End If
             End With
 
Upvote 0
If it is always going to be either just Cancel or that Cancel will appended as the last addition couldn't you just check for Cancel in the last position ?

Rich (BB code):
    Case Left(Target.Value, 6) = "Cancel"
            With Target.Offset(0, -20)
                   If Right(.Value, 6) <> "Cancel" Then
                       .Value = .Value & "-Cancel"
                   End If
             End With
I didn’t even think of that! It worked perfectly, thanks so much!
 
Upvote 0

Forum statistics

Threads
1,225,204
Messages
6,183,573
Members
453,170
Latest member
sameer98

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