Add a character to the end of cell value?

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
270
Office Version
  1. 365
Platform
  1. Windows
Hello,

What's the correct syntax if I want to add a ] to the end of a cell if it doesn't exist?

I have tried
VBA Code:
For a = 2 To lastrow
If Right(Range("E" & a), 1).Value <> "]" Then Range("E" & a).Value = Range("E" & a).Value & "]"
Next a

But this fails with "Runtime error 424: object required".

Many thanks for your thoughts.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I do not see any issues with that code.
What is the value of lastrow?
What do the values in column E look like?
Are they hard-coded, or are there formulas in that column?
 
Upvote 0
I do not see any issues with that code.
What is the value of lastrow?
What do the values in column E look like?
Are they hard-coded, or are there formulas in that column?

Hardcoded, so
Code:
Smith [TR]
Jones [EW]
Harris [SA

I'm trying to trap the third one in that list because it's missing a ] at the end.

lastrow is
VBA Code:
With ActiveSheet
    lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
    lastcol = .Cells(1, Columns.Count).End(xlToLeft).Column
End With
 
Upvote 0
You have the .Value in the wrong place, it should be
VBA Code:
If Right(Range("E" & a).Value, 1) <> "]" Then
 
Upvote 0
Solution
You could also get rid of the loop like
VBA Code:
   With Range("E2:E" & Range("A" & Rows.Count).End(xlUp).Row)
      .Value = Evaluate(Replace("if(@="""","""",if(right(@)=""]"",@,@&""]""))", "@", .Address))
   End With
 
Upvote 0
I missed it as well, so decided to run it & see what happened.
I copied the code, and tried compiling it, and that did not pick up the error. But I did not set up an example to run it on.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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