Solved

Replace Value

Posted on 2011-10-01
3
205 Views
Last Modified: 2012-05-12
Hi,

Is there a way to replace the 1 or 2 in TextBox1.value like the below in VBA code.
I tried to do it like the below code but it did not work.


While i < 15
 
myObject = TextBox + i.Value

Thank you
0
Comment
Question by:samprg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 95

Assisted Solution

by:Lee W, MVP
Lee W, MVP earned 100 total points
ID: 36897063
Convert the variable to a string and then use the replace command.

If you post more of your code, I can try to help you in greater detail. (the code you posted doesn't look right to me in general, but ASSUMING it is, you would:

MyObject = Replace(Replace(TextBox, "1", ""), "2", "") + i.Value

(Seeing more of your code would be VERY helpful - this REALLY doesn't look right, but "replace" almost certainly what you're looking for).
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 400 total points
ID: 36897080
Try as below the 1 to 15 assumes the range of textboxes you are working with is 1 to 15.

The assignment to intTB could be anything ... it simply demonstrates myobkject matches onto each textbox in turn

Chris
Dim intTB As Integer
Dim myobject As Object

    For intTB = 1 To 15
        Set myobject = Me.Controls("textbox" & intTB)
        myobject.Value = intTB
    Next

Open in new window

0
 

Author Closing Comment

by:samprg
ID: 36897388
Awesome
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question