• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

Vb help

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
Gazza83
Asked:
Gazza83
  • 2
  • 2
1 Solution
 
Dave BrettCommented:
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
 
Dave BrettCommented:
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
 
OblivionSYCommented:
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
 
OblivionSYCommented:
Beat me to it :-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now