mylkcha
mylkcha

Reputation: 89

Excel VBA- "Object does not support this property or method" when activating and adding a value to a cell

I get "Object doesn't support this property or method" when using this code

Windows(formatBook).Worksheets(2).Range("B4").Value = title

I just want to put a value on Range B4 of the second sheet of the book in which the sheet name changes

I tried breaking down the code to

Windows(formatBook).Activate
Worksheets(2).Activate
Range("B4").Activate
ActiveCell.Value = title

and it works. Why did it give me the error on the first code and how do I shorten my code?

Upvotes: 2

Views: 462

Answers (1)

user4039065
user4039065

Reputation:

While the Windows collection and Workbooks collection share many properties and methods, they are not completely interchangeable. In this case you need Workbooks.

Workbooks(formatBook).Worksheets(2).Range("B4").Value = title

Upvotes: 1

Related Questions