Changing a text by variable

Rafael NAVARRO

New Member
Joined
Dec 14, 2020
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hello All:

I'm trying to copy and paste several hundreds of lines and then change a value by a variable.

the text to change is ,2, and I want to replace it by a variable (Count) that will be in a loop, nevertheless when trying the code below I just get the Count as text but not the variable number.

could you please help me?

---------------------------------------------------------------------------------------------------------------------
Range(Cells(ren1, col1), Cells(ren1, col2)).Select
Selection.Copy
Count = Count + 1
ren1 = ren1 + 1

Range(Cells(ren1, col1), Cells(ren1, col2)).Select
ActiveSheet.Paste

Selection.Replace What:=",2,", Replacement:=",""Count"",", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi
Try
Count not "Count"
"Count" is text
Count is variable!
 
Upvote 0
Hi
Try
Count not "Count"
"Count" is text
Count is variable!
Hello Mohadin:

By doing that, since there are comas at the beginning and end I will get... ","Count","

When running the code this will generate a Syntax Error
 
Upvote 0
You Are welcome
Thank you for the feedback
Be happy
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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