Solved

Vb help

Posted on 2011-02-14
4
207 Views
Last Modified: 2012-06-22
Please can you help, I'm trying to change the code on the userform.

I want Textbox2 to equal the value held in "DataSheet!B4" and then (+1). So if B4 was equal to "AA-1" when the user form opens the value displayed in textbox2 would be "AA-2"

Private Sub UserForm_Initialize()
TextBox1.Text = VBA.Environ("USERNAME")
TextBox2.Text = "DataSheet!B4"
   
End Sub
 example2.xls
0
Comment
Question by:Gazza83
  • 2
  • 2
4 Comments
 
LVL 50

Expert Comment

by:Dave Brett
ID: 34893310
hth

Dave
Private Sub UserForm_Initialize()
    Dim sArr
    TextBox1.Text = VBA.Environ("USERNAME")
    sArr = Split(Sheets("Data").[B4].Value, "-")
    TextBox2.Text = Val(sArr(1) + 1)
End Sub

Open in new window

0
 
LVL 50

Accepted Solution

by:
Dave Brett earned 500 total points
ID: 34893314
for complete string.

Dave
Private Sub UserForm_Initialize()
    Dim sArr
    TextBox1.Text = VBA.Environ("USERNAME")
    sArr = Split(Sheets("Data").[B4].Value, "-")
    TextBox2.Text = sArr(0) & "-" & Val(sArr(1) + 1)
End Sub

Open in new window

0
 
LVL 3

Expert Comment

by:OblivionSY
ID: 34893326
I am not sure that code re-creates the exact code required.

Private Sub UserForm_Initialize()
    Dim sArr
    TextBox1.Text = VBA.Environ("USERNAME")
    sArr = Split(Sheets("Data").[B4].Value, "-")
    TextBox2.Text = sArr(0) & "-" & Val(sArr(1) + 1)
End Sub

Open in new window

0
 
LVL 3

Expert Comment

by:OblivionSY
ID: 34893329
Beat me to it :-)
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Extract Names Based on Position in the Column 12 29
Excel Cell Total 3 20
Unhide very hidden sheets with password 22 44
Select Next Route by Time 4 19
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
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 …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 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