problem formating text box

Phillip2

Board Regular
Joined
Aug 5, 2019
Messages
79
Office Version
  1. 365
Platform
  1. Windows
I wanted to code a text box so that when anytext was entered it would be formated as [anyTextIVR.aef]. However, if the text box was blank it would remain empty. I was able to do this by using the code

If TBscripts1.Value <> "" Then Cells(LastRow, 31).Value = "[" & TBscripts1.Text & "IVR.aef]"

However, If open a record that already has data in this textbox and save it, it will format the text again. So it appears appear like this [[aaaaIVR.aef]IVR.aef].

I've tried several things to attempt to have it look at the first character and skip if it was a "[", but I 'm not having much luck. What would be the best way to write this?

If TBscripts1.Value <> "" Or Left(TBscripts1.Value, 1) <> "[" Then Cells(LastRow, 31).Value = "[" & TBscripts1.Text & "IVR.aef]"

Then I tried using And.

When I used "And", it would delete and text that was in this box.See the pictures for details.


Thank you any help is appreciated.


____________Scripts Frame________________________

'Scripts



If TBscripts1.Value <> "" And Left(TBscripts1.Value, 1) <> "[" Then Cells(LastRow, 31).Value = "[" & TBscripts1.Text & "IVR.aef]"
If TBscripts2.Value <> "" And Left(TBscripts2.Value, 1) <> "[" Then Cells(LastRow, 32).Value = "[" & TBscripts2.Text & "IVR.aef]"
If TBscripts3.Value <> "" And Left(TBscripts3.Value, 1) <> "[" Then Cells(LastRow, 33).Value = "[" & TBscripts3.Text & "IVR.aef]"
If TBscripts4.Value <> "" And Left(TBscripts4.Value, 1) <> "[" Then Cells(LastRow, 34).Value = "[" & TBscripts4.Text & "IVR.aef]"
If TBscripts5.Value <> "" And Left(TBscripts5.Value, 1) <> "[" Then Cells(LastRow, 35).Value = "[" & TBscripts5.Text & "IVR.aef]"
If TBscripts6.Value <> "" And Left(TBscripts6.Value, 1) <> "[" Then Cells(LastRow, 36).Value = "[" & TBscripts6.Text & "IVR.aef]"
If TBscripts7.Value <> "" And Left(TBscripts7.Value, 1) <> "[" Then Cells(LastRow, 37).Value = "[" & TBscripts7.Text & "IVR.aef]"
If TBscripts8.Value <> "" And Left(TBscripts8.Value, 1) <> "[" Then Cells(LastRow, 38).Value = "[" & TBscripts8.Text & "IVR.aef]"
 

Attachments

  • Capture 1.JPG
    Capture 1.JPG
    153.7 KB · Views: 1
  • Capture 2.JPG
    Capture 2.JPG
    152.6 KB · Views: 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
How about
VBA Code:
If TBscripts1.Value <> "" And Left(TBscripts1.Value, 1) <> "[" Then
   Cells(LastRow, 31).Value = "[" & TBscripts1.Text & "IVR.aef]"
Else
   Cells(LastRow, 31).Value = TBscripts1.Text
End If
 
Upvote 0
I appreciate your help. However I still have a issue. I'm getting a Compile error, Else with If.






VBA Code:
If TBscripts1.Value <> "" And Left(TBscripts1.Value, 1) <> "[" Then Cells(LastRow, 31).Value = "[" & TBscripts1.Text & "IVR.aef]"
Else
Cells(LastRow, 31).Value = TBscripts1.Text
End If


If TBscripts1.Value <> "" And Left(TBscripts2.Value, 1) <> "[" Then Cells(LastRow, 32).Value = "[" & TBscripts1.Text & "IVR.aef]"
Else
Cells(LastRow, 31).Value = TBscripts1.Text
End If


If TBscripts1.Value <> "" And Left(TBscripts3.Value, 1) <> "[" Then Cells(LastRow, 33).Value = "[" & TBscripts1.Text & "IVR.aef]"
Else
Cells(LastRow, 31).Value = TBscripts1.Text
End If

If TBscripts1.Value <> "" And Left(TBscripts4.Value, 1) <> "[" Then Cells(LastRow, 34).Value = "[" & TBscripts1.Text & "IVR.aef]"
Else
Cells(LastRow, 31).Value = TBscripts1.Text
End If

If TBscripts1.Value <> "" And Left(TBscripts5.Value, 1) <> "[" Then Cells(LastRow, 35).Value = "[" & TBscripts1.Text & "IVR.aef]"
Else
Cells(LastRow, 31).Value = TBscripts1.Text
End If

If TBscripts1.Value <> "" And Left(TBscripts6.Value, 1) <> "[" Then Cells(LastRow, 36).Value = "[" & TBscripts1.Text & "IVR.aef]"
Else
Cells(LastRow, 31).Value = TBscripts1.Text
End If

If TBscripts1.Value <> "" And Left(TBscripts7.Value, 1) <> "[" Then Cells(LastRow, 37).Value = "[" & TBscripts1.Text & "IVR.aef]"
Else
Cells(LastRow, 31).Value = TBscripts1.Text
End If

If TBscripts1.Value <> "" And Left(TBscripts8.Value, 1) <> "[" Then Cells(LastRow, 38).Value = "[" & TBscripts1.Text & "IVR.aef]"
Else
Cells(LastRow, 31).Value = TBscripts1.Text
End If
 
Upvote 0
You need to do it like I showed in post#2.

Also when posting code, please use code tags the <vba/> icon in the reply window. It makes it a lot easier to read.
 
Upvote 0
It's amazing what happens when you write it correctly. Thank you so much.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,197
Latest member
k_bs

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