0

I´m using VBA userforms to fill values from the textboxes into cells of a specific sheet. Lets says the Sheet is named "Sheet1", the textbox is called "TextBox1" and the cell is "C2". I´m currently using

ThisWorkbook.Sheet1.Range("c2").value = Userform1.TextBox1.Value

to fill the cell with the value that I have typed into the textbox. Now I have experienced that when I have multiple copies of the same document opened, it doesnt always put the value in the intended document, but into the copy (which also has a sheet called "Sheet1"). Is there a way around that problem?

MarkAKE
  • 45
  • 1
  • 8
  • 2
    If **multiple copies** means different names, `ThisWorkbook` **will always refer the workbook where the running code exists**. Then, a sheet named **Sheet1** and `ThisWorkbook.Sheet1` can be different in some circumstances. Worksheet **name** and worksheet **code name** may be different... But if what you show is not true, and the code uses `ActiveWorkbook.Sheet1` instead of `ThisWorkbook.Sheet1`, it will use `sheet1` of the **Active Workbook**. – FaneDuru Aug 11 '22 at 09:33
  • Please, read [Difference between Thisworkbook.name and Activeworkbook.name in VBA](https://stackoverflow.com/questions/35426907/difference-between-thisworkbook-name-and-activeworkbook-name-in-vba) – Foxfire And Burns And Burns Aug 11 '22 at 09:44

0 Answers0