title: VBA Place Userform Next to Selected Range
body: <p>I need to place a userform next to a selected cell. Here's my code. Excel 2013.</p>
  
  <p>In the userform module:</p>
  
  <pre><code>Private rangePosition As Range 'Property passed to form to set position based on range
  
  'Set userform position to right of range
  Property Let PositionToRange(rangeInput As Range)
      Set rangePosition = rangeInput
      Me.Left = rangePosition.Left + rangePosition.Width + 30
      Me.Top = rangePosition.Top + Application.CommandBars("Ribbon").Height + 27
  End Property
  </code></pre>
  
  <p>In a standard module:</p>
  
  <pre><code>userform.PositionToRange = Selection '(or some specified range)
  userform.Show
  </code></pre>
  
  <p>Okay, great. So at first this seemed to do the trick. However, it only seems to work in the standard view when Excel first loads, with the first 30 rows or so. However, if you try to use it on, say, row 4000, or even 40, it places the userform WAY off the screen. Excel doesn't seem to take the position of the screen into account. To see what I mean, try using the code above to place a userform next to cell A1. Then scroll down so A1 is no longer on the screen and run the code again. It puts the userform in exactly the same place, as if you were still scrolled up in the original position.</p>
  
  <p>Is there an attribute I can use other than <code>range.Left</code>, etc to place the userform relative to where the range is on the screen? Or do I need to do some weird voodoo crap where I figure out the position of the scroll bar and find the position of the cell relative to that, after factoring in the rotational force of the earth and relative distance from the sun, of course?</p>
  
  <p>Oh, Microsoft...</p>