+ Reply to Thread
Results 1 to 2 of 2

Using text box input to lookup number and replace based on user input into new column

  1. #1
    Registered User
    Join Date
    11-23-2011
    Location
    london, england
    MS-Off Ver
    10
    Posts
    7

    Using text box input to lookup number and replace based on user input into new column

    Hi All
    Getting into this VBA but am stuck using msg box to create a new column based on user input
    I have a table with column D & E containing variable data, these will be numeric values,
    I am trying to create a msg box that will ask" Do you need to change any VLAN numbers" if the answer is yes, it will ask for the number then look in column D and where it finds that number it will put the new user input number into a new column at the end of the table in the same row. If the user input is no then it will juts put the existing numbers in column D into the last column with a header of NEW VLAN and then loop to a new msg box this time asking "Do you want to change any Voice VLAN numbers" and repeat the above against column E putting the new info into the last column in the same row number with the column header changed to New Voice VLAN.
    The last thing that would be useful is if the changes could have their cells coloured red.

    Thanks for your excellent help in advanced

  2. #2
    Registered User
    Join Date
    11-23-2011
    Location
    london, england
    MS-Off Ver
    10
    Posts
    7

    Re: Using text box input to lookup number and replace based on user input into new co

    Hi Guys
    I have come across the below code that will work to some extent but am trying to add a loop that will return it to the beginning so that x number of numbers can be changed. on each sub routine
    Sub VLANChanger()
    Dim userfind As String
    Dim userchange As String
    'add colums old vlans to end ready for chnage
    Columns("D:E").Select
    Selection.Copy
    Columns("L:M").Select
    ActiveSheet.Paste
    Range("L1").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "New VLAN"
    Range("M1").Select
    ActiveCell.FormulaR1C1 = "New Voice VLAN"
    Range("L1").Select
    Set R = Range("L:L") '<--set your range here

    userfind = InputBox(Prompt:="Do you want to Change Any VLAN Numbers.", Title:="Change VLANS", Default:="Enter Old VLAN Number Here")
    If userfind = "defaultvalue" Or userfind = vbNullString Then
    MsgBox ("You need to enter something")
    Exit Sub
    End If

    R.Select

    Dim foundRange As Range
    Set foundRange = Selection.Find(What:=userfind)
    If foundRange Is Nothing Then
    MsgBox ("No such value exists")
    Exit Sub
    End If


    userchange = InputBox(Prompt:="What is the New VLAN Number", Title:="New VLAN?", Default:=userfind)
    If userchange = "defaultvalue" Or userchange = vbNullString Then
    MsgBox ("You need to enter something")
    Exit Sub
    Else

    For Each cell In R
    If cell.Value = userfind Then
    cell.Value = userchange


    End If
    Next
    End If
    End Sub
    then it runs
    Sub VoiceVLANChanger()
    Dim userfind As String
    Dim userchange As String

    Set R = Range("M:M") '<--set your range here

    userfind = InputBox(Prompt:="Do you want to Change Any VoiceVLAN Numbers.", Title:="Change VoiceVLANS", Default:="Enter Old VoiceVLAN Number Here")
    If userfind = "defaultvalue" Or userfind = vbNullString Then
    MsgBox ("You need to enter something")
    Exit Sub
    End If

    R.Select

    Dim foundRange As Range
    Set foundRange = Selection.Find(What:=userfind)
    If foundRange Is Nothing Then
    MsgBox ("No such value exists")
    Exit Sub
    End If


    userchange = InputBox(Prompt:="What is the New VoiceVLAN Number", Title:="New VoiceVLAN?", Default:=userfind)
    If userchange = "defaultvalue" Or userchange = vbNullString Then
    MsgBox ("You need to enter something")
    Exit Sub
    Else

    For Each cell In R
    If cell.Value = userfind Then
    cell.Value = userchange


    End If
    Next
    End If
    End Sub

    This code does the trick but was not as 'simple' as I originally wanted it.
    I currently use the following to run it against both columns
    VoiceVLANChanger but as it only runs once per sub routine and i have x number of VLANS i want it to loop until the user does not enter anything and then it ends and the next sub routine run


    Thanks n advance

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1