command button code changing sheet name

Godders199

Active Member
Joined
Mar 2, 2017
Messages
313
Office Version
  1. 2013
Hello, i have the following code for a command button, however currently whenever i select a name via the message box the sheet name changes to that name

I cannot see anything in my code to do this... Can only think i have pressed or selected something in error. just cant find it.

Any ideas why the tab name changes?

Private Sub CommandButton1_Click()


DimproductRow As Long
Dim productNameAs String

Name =InputBox("What is Advisers name?")

On Error GoToerrNotFound
agentRow =Sheets("Advisers").Range("c:c").Find(What:=Name).row
On Error GoTo 0
MsgBoxSheets("Advisers").Range("C1").Value & " - "& Sheets("Advisers").Range("C" & agentRow).Value& vbNewLine & _
Sheets("Advisers").Range("A1").Value& " - " & Sheets("Advisers").Range("A"& agentRow).Value & vbNewLine & _
Sheets("Advisers").Range("B1").Value& " - " & Sheets("Advisers").Range("B"& agentRow).Value & vbNewLine & _
Sheets("Advisers").Range("C1").Value & " -" & Sheets("Advisers").Range("C" &agentRow).Value & vbNewLine & _
Sheets("Advisers").Range("d1").Value& " - " & Sheets("Advisers").Range("D"& agentRow).Value & vbNewLine & _
Sheets("Advisers").Range("f1").Value & " -" & Sheets("Advisers").Range("f" &agentRow).Value & vbNewLine & _
Sheets("Advisers").Range("aa1").Value & " -" & Sheets("Advisers").Range("aa" &agentRow).Value & vbNewLine & _
Sheets("Advisers").Range("h1").Value& " - " & Sheets("Advisers").Range("h"& agentRow).Value & vbNewLine & _
Sheets("Advisers").Range("m1").Value& " - " & Sheets("Advisers").Range("m"& agentRow).Value & vbNewLine & _
Sheets("Advisers").Range("i1").Value& " - " & Sheets("Advisers").Range("i"& agentRow).Value & vbNewLine & _
Sheets("Advisers").Range("j1").Value& " - " & Sheets("Advisers").Range("j"& agentRow).Value & vbNewLine & _
Sheets("Advisers").Range("k1").Value& " - " & Sheets("Advisers").Range("k"& agentRow).Value & vbNewLine & _
Sheets("Advisers").Range("ac1").Value& " - " & Sheets("Advisers").Range("ac"& agentRow).Value & vbNewLine & _
Sheets("Advisers").Range("ae1").Value& " - " & Sheets("Advisers").Range("ae"& agentRow).Value


Exit Sub
errNotFound:
MsgBox"Adviser name not found, has to be the same as in Hierarchy!",vbCritical
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi,

Take a look at the worksheet module ... and look for any event macro which generates the new sheet name ... :wink:

HTH
 
Last edited:
Upvote 0
A few questions.
1) Where is the commandbutton? If it's on a sheet, which sheet?
2) Is it the "Advisers" sheet that is getting it's name changed?
3) If you enter a valid Adviser name in the input box, do you get the MsgBox appear with the correct info?
 
Upvote 0
Hello in answer to your questions
1/ button is on a sheet called "homepage"
2/ it the homepage shet that the name changes
3/ yes the message bo displays all the correct information

All i had done is copy the code from another cmmand button which searched by another criteria and that does not change the sheet name.

Just to confirm it is when i press ok to close message box the sheet name changes
 
Last edited:
Upvote 0
Hi,

Take a look at the worksheet module ... and look for any event macro which generates the new sheet name ... :wink:

HTH
 
Upvote 0
Hi thanks , i wrote the code, i do not know how to rename a sheet. so that is not in there.
 
Upvote 0
There is nothing in your code that changes the sheet name.
Also, as your code is not selecting/changing anything, it should not be triggering any Event code.
So without access to the file, I cannot think of what maybe causing it.
 
Upvote 0
thanks Fluff for your reply you are always very helpful. it is appreciated. I have clearly done something , think i will delete the command button and start again.
 
Upvote 0

Forum statistics

Threads
1,215,982
Messages
6,128,099
Members
449,419
Latest member
mammothzaa

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