ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Type mismatch... (https://www.excelbanter.com/excel-discussion-misc-queries/170121-type-mismatch.html)

George[_4_]

Type mismatch...
 
When running the following Visual Basic code a run time error occurs
saying that there is a type mismatch. The name txtRemoveSheet is from a
textbox. My assumption was that it should be of type string and that
the Delete method accepted strings. Is this assumption correct? I
don't see why txtRemoveSheet is not accepted, can someone enlighten me?

Private Sub cmdDelete_Click()
Worksheets(txtRemoveSheet).Delete
txtRemoveSheet.Text = ""
End Sub

Thank you,
George

Dave Peterson

Type mismatch...
 
I don't know why it didn't work for you. Maybe it has something to do with
what's in that textbox???

You may want to share that value.

George wrote:

When running the following Visual Basic code a run time error occurs
saying that there is a type mismatch. The name txtRemoveSheet is from a
textbox. My assumption was that it should be of type string and that
the Delete method accepted strings. Is this assumption correct? I
don't see why txtRemoveSheet is not accepted, can someone enlighten me?

Private Sub cmdDelete_Click()
Worksheets(txtRemoveSheet).Delete
txtRemoveSheet.Text = ""
End Sub

Thank you,
George


--

Dave Peterson

George[_4_]

Type mismatch...
 
Is it a good idea to initialize string variables before using them? How
and where would I initialize txtRemoveSheet to an empty string before
the subroutine is called?

What do you mean by "share that value"?

Thanks for the reply,
George

Dave Peterson wrote:
I don't know why it didn't work for you. Maybe it has something to do with
what's in that textbox???

You may want to share that value.

George wrote:
When running the following Visual Basic code a run time error occurs
saying that there is a type mismatch. The name txtRemoveSheet is from a
textbox. My assumption was that it should be of type string and that
the Delete method accepted strings. Is this assumption correct? I
don't see why txtRemoveSheet is not accepted, can someone enlighten me?

Private Sub cmdDelete_Click()
Worksheets(txtRemoveSheet).Delete
txtRemoveSheet.Text = ""
End Sub

Thank you,
George



Dave Peterson

Type mismatch...
 
I guessed that your code was taken from a button on a userform. I also guessed
that txtRemoveSheet was the name of a textbox on that userform.

I could have been wrong in both cases.

If I was correct in my guesses, then I don't see a need to initialize the value
in that textbox.

And by share the value, I was asking what that textbox (or variable named
txtremovesheet) actually held.



George wrote:

Is it a good idea to initialize string variables before using them? How
and where would I initialize txtRemoveSheet to an empty string before
the subroutine is called?

What do you mean by "share that value"?

Thanks for the reply,
George

Dave Peterson wrote:
I don't know why it didn't work for you. Maybe it has something to do with
what's in that textbox???

You may want to share that value.

George wrote:
When running the following Visual Basic code a run time error occurs
saying that there is a type mismatch. The name txtRemoveSheet is from a
textbox. My assumption was that it should be of type string and that
the Delete method accepted strings. Is this assumption correct? I
don't see why txtRemoveSheet is not accepted, can someone enlighten me?

Private Sub cmdDelete_Click()
Worksheets(txtRemoveSheet).Delete
txtRemoveSheet.Text = ""
End Sub

Thank you,
George



--

Dave Peterson

George[_4_]

Type mismatch...
 
Your guesses were correct.

The variable txtRemoveSheet stores the value from a textbox on a
userform. The variable is the string name of a worksheet that is to be
deleted. For testing purposes I made sure that the string in the
textbox is a valid worksheet name.

Dave Peterson wrote:
I guessed that your code was taken from a button on a userform. I also guessed
that txtRemoveSheet was the name of a textbox on that userform.

I could have been wrong in both cases.

If I was correct in my guesses, then I don't see a need to initialize the value
in that textbox.

And by share the value, I was asking what that textbox (or variable named
txtremovesheet) actually held.



George wrote:
Is it a good idea to initialize string variables before using them? How
and where would I initialize txtRemoveSheet to an empty string before
the subroutine is called?

What do you mean by "share that value"?

Thanks for the reply,
George

Dave Peterson wrote:
I don't know why it didn't work for you. Maybe it has something to do with
what's in that textbox???

You may want to share that value.

George wrote:
When running the following Visual Basic code a run time error occurs
saying that there is a type mismatch. The name txtRemoveSheet is from a
textbox. My assumption was that it should be of type string and that
the Delete method accepted strings. Is this assumption correct? I
don't see why txtRemoveSheet is not accepted, can someone enlighten me?

Private Sub cmdDelete_Click()
Worksheets(txtRemoveSheet).Delete
txtRemoveSheet.Text = ""
End Sub

Thank you,
George



Dave Peterson

Type mismatch...
 
I couldn't get my test code to fail in that manner (type mismatch).

What's the name of the sheet that you tested with? You still haven't shared
that.



George wrote:

Your guesses were correct.

The variable txtRemoveSheet stores the value from a textbox on a
userform. The variable is the string name of a worksheet that is to be
deleted. For testing purposes I made sure that the string in the
textbox is a valid worksheet name.

Dave Peterson wrote:
I guessed that your code was taken from a button on a userform. I also guessed
that txtRemoveSheet was the name of a textbox on that userform.

I could have been wrong in both cases.

If I was correct in my guesses, then I don't see a need to initialize the value
in that textbox.

And by share the value, I was asking what that textbox (or variable named
txtremovesheet) actually held.



George wrote:
Is it a good idea to initialize string variables before using them? How
and where would I initialize txtRemoveSheet to an empty string before
the subroutine is called?

What do you mean by "share that value"?

Thanks for the reply,
George

Dave Peterson wrote:
I don't know why it didn't work for you. Maybe it has something to do with
what's in that textbox???

You may want to share that value.

George wrote:
When running the following Visual Basic code a run time error occurs
saying that there is a type mismatch. The name txtRemoveSheet is from a
textbox. My assumption was that it should be of type string and that
the Delete method accepted strings. Is this assumption correct? I
don't see why txtRemoveSheet is not accepted, can someone enlighten me?

Private Sub cmdDelete_Click()
Worksheets(txtRemoveSheet).Delete
txtRemoveSheet.Text = ""
End Sub

Thank you,
George



--

Dave Peterson

George[_4_]

Type mismatch...
 
The name of the sheet is "Sheet3".

Dave Peterson wrote:
I couldn't get my test code to fail in that manner (type mismatch).

What's the name of the sheet that you tested with? You still haven't shared
that.



George wrote:
Your guesses were correct.

The variable txtRemoveSheet stores the value from a textbox on a
userform. The variable is the string name of a worksheet that is to be
deleted. For testing purposes I made sure that the string in the
textbox is a valid worksheet name.

Dave Peterson wrote:
I guessed that your code was taken from a button on a userform. I also guessed
that txtRemoveSheet was the name of a textbox on that userform.

I could have been wrong in both cases.

If I was correct in my guesses, then I don't see a need to initialize the value
in that textbox.

And by share the value, I was asking what that textbox (or variable named
txtremovesheet) actually held.



George wrote:
Is it a good idea to initialize string variables before using them? How
and where would I initialize txtRemoveSheet to an empty string before
the subroutine is called?

What do you mean by "share that value"?

Thanks for the reply,
George

Dave Peterson wrote:
I don't know why it didn't work for you. Maybe it has something to do with
what's in that textbox???

You may want to share that value.

George wrote:
When running the following Visual Basic code a run time error occurs
saying that there is a type mismatch. The name txtRemoveSheet is from a
textbox. My assumption was that it should be of type string and that
the Delete method accepted strings. Is this assumption correct? I
don't see why txtRemoveSheet is not accepted, can someone enlighten me?

Private Sub cmdDelete_Click()
Worksheets(txtRemoveSheet).Delete
txtRemoveSheet.Text = ""
End Sub

Thank you,
George



Dave Peterson

Type mismatch...
 
I couldn't get a type mismatch error in any of my testing.

George wrote:

The name of the sheet is "Sheet3".

Dave Peterson wrote:
I couldn't get my test code to fail in that manner (type mismatch).

What's the name of the sheet that you tested with? You still haven't shared
that.



George wrote:
Your guesses were correct.

The variable txtRemoveSheet stores the value from a textbox on a
userform. The variable is the string name of a worksheet that is to be
deleted. For testing purposes I made sure that the string in the
textbox is a valid worksheet name.

Dave Peterson wrote:
I guessed that your code was taken from a button on a userform. I also guessed
that txtRemoveSheet was the name of a textbox on that userform.

I could have been wrong in both cases.

If I was correct in my guesses, then I don't see a need to initialize the value
in that textbox.

And by share the value, I was asking what that textbox (or variable named
txtremovesheet) actually held.



George wrote:
Is it a good idea to initialize string variables before using them? How
and where would I initialize txtRemoveSheet to an empty string before
the subroutine is called?

What do you mean by "share that value"?

Thanks for the reply,
George

Dave Peterson wrote:
I don't know why it didn't work for you. Maybe it has something to do with
what's in that textbox???

You may want to share that value.

George wrote:
When running the following Visual Basic code a run time error occurs
saying that there is a type mismatch. The name txtRemoveSheet is from a
textbox. My assumption was that it should be of type string and that
the Delete method accepted strings. Is this assumption correct? I
don't see why txtRemoveSheet is not accepted, can someone enlighten me?

Private Sub cmdDelete_Click()
Worksheets(txtRemoveSheet).Delete
txtRemoveSheet.Text = ""
End Sub

Thank you,
George



--

Dave Peterson


All times are GMT +1. The time now is 02:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com