ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Is it possible to loop through text? (https://www.excelbanter.com/excel-programming/411735-possible-loop-through-text.html)

Sam Kuo[_3_]

Is it possible to loop through text?
 
Is it possible to loop through text, as it would for number? For example:

Dim Text As Integer ' where Text = "Before", "Now", or "After"
For Text
' code goes here
' i.e. Me.Controls("txt" & Text).Visible = True
Next Text

Bob Phillips

Is it possible to loop through text?
 
Dim sText As String
Dim ary As Variant
Dim i As Long

sText = "Before,Now,After"
ary = Split(sText, ",")
For i = LBound(ary) To UBound(ary)

'Me.Controls("txt" & ary(i)).Visible = True


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Sam Kuo" wrote in message
...
Is it possible to loop through text, as it would for number? For example:

Dim Text As Integer ' where Text = "Before", "Now", or "After"
For Text
' code goes here
' i.e. Me.Controls("txt" & Text).Visible = True
Next Text




Rick Rothstein \(MVP - VB\)[_2027_]

Is it possible to loop through text?
 
It can be done this way also...

Dim V As Variant
For Each V In Split("Before,Now,After", ",")
Me.Controls("txt" & V).Visible = True
Next

Rick


"Bob Phillips" wrote in message
...
Dim sText As String
Dim ary As Variant
Dim i As Long

sText = "Before,Now,After"
ary = Split(sText, ",")
For i = LBound(ary) To UBound(ary)

'Me.Controls("txt" & ary(i)).Visible = True


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Sam Kuo" wrote in message
...
Is it possible to loop through text, as it would for number? For example:

Dim Text As Integer ' where Text = "Before", "Now", or "After"
For Text
' code goes here
' i.e. Me.Controls("txt" & Text).Visible = True
Next Text





Sam Kuo[_3_]

Is it possible to loop through text?
 
Hi Bob and Rick
Thanks alot!

"Rick Rothstein (MVP - VB)" wrote:

It can be done this way also...

Dim V As Variant
For Each V In Split("Before,Now,After", ",")
Me.Controls("txt" & V).Visible = True
Next

Rick


"Bob Phillips" wrote in message
...
Dim sText As String
Dim ary As Variant
Dim i As Long

sText = "Before,Now,After"
ary = Split(sText, ",")
For i = LBound(ary) To UBound(ary)

'Me.Controls("txt" & ary(i)).Visible = True


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Sam Kuo" wrote in message
...
Is it possible to loop through text, as it would for number? For example:

Dim Text As Integer ' where Text = "Before", "Now", or "After"
For Text
' code goes here
' i.e. Me.Controls("txt" & Text).Visible = True
Next Text







All times are GMT +1. The time now is 07:23 PM.

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