Solved

Vb help

Posted on 2011-02-14
4
205 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now