Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you want to take a range from a specific sheet, use that sheet before the range:</p> <pre><code>Sheet1.Range("D" &amp; i).Value = TextBox1 'takes cell from first sheet. Sheet2.Range..... 'takes cell from second sheet. ActiveWorkbook.Worksheets("SheetName").Range.... 'you get sheets by their names </code></pre> <p>You can also put the sheet into a variable so you keep using it instead of repeating sheet name all over:</p> <pre><code>Dim TargetSheet as Worksheet Set TargetSheet = ActiveWorkbook.Worksheets("SheetName") TargetSheet.Range..... TargetSheet.Range...... TargetSheet.Range...... </code></pre> <hr> <p>So your code could be like this:</p> <pre><code>Private Sub CommandButton1_Click() 'First thing: select your specific sheet: Dim MySheet as Worksheet Set MySheet = ActiveWorkbook.Worksheets("TheNameOfYourSheet") 'Now, before every range or cell, take them FROM that specific sheet i = MySheet.Cells(Rows.Count, 1).End(xlUp).Row + 23 'Get last empty cell in column A 'Select your pivot cell (don't forget MySheet) Dim PivotCell as Range Set PivotCell = MySheet.Range("D" &amp; i) 'Put the value in the pivot PivotCell.Value = TextBox1 'Now you can start using the offsets (it's really better, as you commented) PivotCell.Offset(0,1).Value = TextBox4 'That would be D2 if Pivot is D1 'I'm not sure if you can use negative offsets, 'if not, take the top left cell of your target area as pivot - 'But there surely will be an error if the offset falls to the left or above A1 PivotCell.Offset(3, -1).Value = TextBox2 'That is C4 - PivotCell.Offset(4,-1).Value = TextBox3 'C5 If OptionButton1.Value = True Then PivotCell.Offset(6,-3).Value = OptionButton1.Caption ' A7 ElseIf OptionButton2.Value = True Then PivotCell.Offset(6,-3).Value = OptionButton2.Caption ElseIf OptionButton3.Value = True Then PivotCell.Offset(6,-3).Value = OptionButton3.Caption Else PivotCell.Offset(6,-3).Value = OptionButton4.Caption End If Unload Me End Sub </code></pre> <p>One thing EVEN BETTER is to <code>Name</code> a cell. In the top left of the Excel screen, there is a text box where the selected cell coordinates are show (like "A1", "B2", ...). If you type a name in that box, you can use that named cell via code like this:</p> <pre><code>ActiveSheet.Range("NamedCell") </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload