0

I'm confused on how to update a Range variable with the current cell. Say I have the following:

Dim site_curr_position As Range
Set site_curr_position = Worksheets("newsheet").Range("D14")
Set site_curr_position = Worksheets("newsheet").Range("E14")
Worksheets("newsheet").Range("A4").Select
'Set site_curr_position = ?

How do I get the range of that cell where the cursor is now placed?

Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235
simplycoding
  • 2,770
  • 9
  • 46
  • 91
  • In your example, should site_curr_position be Range("A4")? – zedfoxus Apr 24 '19 at 20:29
  • 2
    In general, you should always try to avoid using `.Activate` and `.Select`. Relying on those is largely considered bad practice. See [here](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba?rq=1) for why. To answer your question however, it would simply be `Set site_curr_position = Selection` – tigeravatar Apr 24 '19 at 20:30
  • `ActiveCell` gets you the cell that's currently active... but please read the link @tigeravatar posted. FWIW the second assignment is voiding the first. – Mathieu Guindon Apr 24 '19 at 21:05

0 Answers0