How to add additional text to cell reference in VBA

EAG1

New Member
Joined
Feb 12, 2021
Messages
23
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I want the following VBA code to look for the cell reference + "_1" in my code and cannot work it out. I am quite new to VBA.

My current line goes:

For Each cel In Range("B2", Range("B" & Rows.Count).End(xlUp))

Could someone help me add "B2"&"_1" into the code because this doesn't work.

My data is as follows. It is used to look up images in my files.

11461
21051
14924

I want the code to look for the following but not change the data.

11461_1
21051_1
14924_1

Many thanks for your help.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi,
try this
Sub addsomething()

Dim mycell As Range
For Each mycell In ActiveSheet.UsedRange.Columns("B").Cells
mycell.Value = mycell.Value & "_1"
Next mycell
End Sub
 
Upvote 0
Your code
VBA Code:
Sub test()
Dim cel As Range
For Each cel In Range("B2", Range("B" & Rows.Count).End(xlUp))
cel = cel & "_1"
Next
End Sub
 
Upvote 0
Another option
VBA Code:
Sub EAG()
   With Range("B2", Range("B" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("If(@="""","""",@&""_1"")", "@", .Address))
   End With
End Sub
 
Upvote 0
Solution
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,893
Members
449,194
Latest member
JayEggleton

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