Capture the range a user selects and put in textbox.

  • Thread starter Thread starter Drew
  • Start date Start date
D

Drew

Hi,
I am trying to capture the range a user selects then put that
information into a textbox in a userform. That's the start cell and
end cell addresses, not the contents.

I have a Userform with an Excel workbook. The user is going to
highlight a range of cells in any worksheet in any workbook () and I
want the following details to be shown in text-boxes in my Userform.
The data I need is:

Workbook Name
Worksheet Name
First Cell of the range selected
Last Cell of the range selected.

Does anyone have any ideas? I thought there would be some way of
converting a Range to a String, but I didn't very far down that route.

Thanks in advance!
Drew.
 
Hi

sub test()
dim start as string, finish as string
With Selection
start = .Cells(1,1).address is the first cell
finish = .Cells(.rows.count, .columns.count).address
End With
msgbox start
msgbox finish

end sub

regards
Paul
 
tbWB.Value = Selection.parent.Parent.Name
tbWS.Value = Selection.Parent.Name
tbFirstCell.Value = Selection(1).Address
tbLastCell.Value = Selection(Selection.Count).Address

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top