ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   choose range name according to cell (https://www.excelbanter.com/excel-programming/393120-choose-range-name-according-cell.html)

JSuarez

choose range name according to cell
 
Hi,

I need to choose among different ranges depending on the value of one cell.
for example, if the value of cell A1 is "IT", I need to subtitute all "GE"
text in a range cells with "IT".

Here is what I have, but it works for only one case. I need for 21 different
choices in cell A1.



Range("D6:E111,H6:I111,L6:M111,M113,L113,I113,H113 ,E113,D113,M224,L224,I224,H224,E224,D224").Select

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

Is there any kind of loop for this?

JLGWhiz

choose range name according to cell
 
If your Range of cells to be replace remain constant and only the value of
Range("A1") changes, Then you could use a reference to the value of
Range("A1") like this:

x = Range("A1").Value

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


"JSuarez" wrote:

Hi,

I need to choose among different ranges depending on the value of one cell.
for example, if the value of cell A1 is "IT", I need to subtitute all "GE"
text in a range cells with "IT".

Here is what I have, but it works for only one case. I need for 21 different
choices in cell A1.



Range("D6:E111,H6:I111,L6:M111,M113,L113,I113,H113 ,E113,D113,M224,L224,I224,H224,E224,D224").Select

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

Is there any kind of loop for this?



All times are GMT +1. The time now is 05:12 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com