Concatenation yields error with underscore

Posted by Daniel on Stack Overflow See other posts from Stack Overflow or by Daniel
Published on 2010-05-27T20:31:23Z Indexed on 2010/05/28 12:22 UTC
Read the original article Hit count: 134

Filed under:
|

I am trying to create a macro that brings in the name of the sheet and combine it with text. For example, for sheet one, I want it to say "ThisIs_Sheet1_Test" in I5 of Sheet1. There are several sheets but it should work for all of them.

What is wrong with my code? I think the underscore might be ruining it all. Here's what I have:

Dim SheetName As String

Public Sub CommandButton1_Click()

SheetName = ActiveSheet.Name

Sheets("Sheet1").Range("I5", "I5") = ThisIs_" & SheetName.text & "_Test
Sheets("Sheet2").Range("H5", "H5") = ThisIs_" & SheetName.text & "_Test
Sheets("Sheet3").Range("G5", "G5") = ThisIs_" & SheetName.text & "_Test

End Sub

© Stack Overflow or respective owner

Related posts about vba

Related posts about excel-vba