0

I'm fully new with Excel VBA and struggling already for hours to use a string variable instead of writing the string. Probably a very simple solution, however I cannot seem to find similar cases nor did anything I tried work out :s

I define a variable name NewSbWb (= "REQ1351") as following

Dim NewSbWb As String
NewSbWb = ActiveWorkbook.Sheets(1).Range("D2").Value

if I then use functions such as the following:

Workbooks("REQ1351").Activate

or

currentSheet.Copy Before:=Workbooks("REQ1351").Sheets(sheetIndex)

I would like to use the string variable NewSbWb instead of writing "REQ1351".

I hope one of you can help me. Many thanks in advance!

1
  • Simply: Workbooks(NewSbWb).Activate Commented Jun 29, 2015 at 13:31

1 Answer 1

1
Dim NewSbWb As String
NewSbWb = ActiveWorkbook.Sheets(1).Range("D2").Value
Workbooks(NewSbWb).Activate
currentSheet.Copy Before:=Workbooks(NewSbWb).Sheets(sheetIndex)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.