Starting a Macro where the cursor is

  • Thread starter tayseer.abdelhalim
  • Start date
T

tayseer.abdelhalim

I recorded a macro to chart a range of data. But since the data can be
at any cell in the worksheet, I would like to generalize the macro by
telling it to start at the cell where the cursor happens to be.....I
would appreciate it if someone can tell me the code to do that

Tayseer
 
G

Guest

You could use Selection.[do something] or ActiveCell.[do something]
but I would give it some serious thought before doing either. Maybe a
Workbook_Open event or a Worksheet_Change event would be a better approach.
 
G

Guest

Hi Tayseer, after reading your post again, I think using the Selection.[do
something] approach would work. Disregard my suggestions about the
Workbook_Open and Worksheet_Change events. I had read your post as needing
something to trigger the macro instead of designating the starting point.
However, it is advisable to minimize the use of the Selection method as much
a possible. The code runs more efficiently if you use code that gives direct
instruction like
Sheet(1).Range("B5").[do something]
 
T

tayseer.abdelhalim

Hi Tayseer, after reading your post again, I think using the Selection.[do
something] approach would work. Disregard my suggestions about the
Workbook_Open and Worksheet_Change events. I had read your post as needing
something to trigger the macro instead of designating the starting point.
However, it is advisable to minimize the use of the Selection method as much
a possible. The code runs more efficiently if you use code that gives direct
instruction like
Sheet(1).Range("B5").[do something]



I recorded a macro to chart a range of data. But since the data can be
at any cell in the worksheet, I would like to generalize the macro by
telling it to start at the cell where the cursor happens to be.....I
would appreciate it if someone can tell me the code to do that
Tayseer- Hide quoted text -

- Show quoted text -

Thanx so much..I'll try it

Tayseer
 
T

tayseer.abdelhalim

Hi Tayseer, after reading your post again, I think using the Selection.[do
something] approach would work. Disregard my suggestions about the
Workbook_Open and Worksheet_Change events. I had read your post as needing
something to trigger the macro instead of designating the starting point.
However, it is advisable to minimize the use of the Selection method as much
a possible. The code runs more efficiently if you use code that gives direct
instruction like
Sheet(1).Range("B5").[do something]



I recorded a macro to chart a range of data. But since the data can be
at any cell in the worksheet, I would like to generalize the macro by
telling it to start at the cell where the cursor happens to be.....I
would appreciate it if someone can tell me the code to do that
Tayseer- Hide quoted text -

- Show quoted text -

Sorry to bother you, but I am new to VBA. Here is the code that I
currently have:

Sub chart_test()
ActiveCell.CurrentRegion.Select
Set tbl = ActiveCell.CurrentRegion
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=tbl
End Sub

Thanx for all the help

Tayseer
 

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

Top