Get Data from Selected Cells

  • Thread starter Thread starter Ben Crinion
  • Start date Start date
B

Ben Crinion

Hi

I have added a button onto a toolbar and now i want to be able to get the
data from the selected cells when the button is clicked.

I cant work out how to do this and any pointers in the right direction would
be greatly recieved.

Im using VB6 to create an AddIn not VBA.

Thanks
Ben Crinion
 
In case the cell you need data from is not the active cell
use something like the following:

myvariable = worksheets("Sheet1").range("A1").value

or

myvariable = worksheets("Sheet1").cells(cRow, cCol)

where cRow and cCol are integer variables you set
dynamically depending on your need.

Hope that helps!

Kevin
 
..... gives me this error

Object variable or With block variable not set
 
oXL is an Excel.application

Private Sub butt_SendSMS_Click(ByVal Ctrl As Office.CommandBarButton, _
canceldefault As Boolean)
On Error GoTo err_SendSMS_Click

MsgBox ActiveCell.Value
MsgBox oXL.Worksheets("Sheet1").Range("A1").Value


err_SendSMS_Click:
Debug.Print Err.Description
End Sub
 
If oxl is excel.application, then shouldn't you have:

MsgBox oXL.workbooks("book1.xls").Worksheets("Sheet1").Range("A1").Value

and maybe...
msgbox oxl.activecell.value
would work???

but if you look at VBA's help for ActiveCell, there's a remark that may affect
you:

If you don't specify an object qualifier, this property returns the active cell
in the active window.

Be careful to distinguish between the active cell and the selection. The active
cell is a single cell inside the current selection. The selection may contain
more than one cell, but only one is the active cell.

The following expressions all return the active cell, and are all equivalent.

ActiveCell
Application.ActiveCell
ActiveWindow.ActiveCell
Application.ActiveWindow.ActiveCell
 

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