Help with an Excel macro

V

Victor Delta

Can anyone please help me with some code for a macro that will achieve the
following in an Excel spreadsheet:


1. Go to 'Clients' worksheet if currently on another worksheet

2. Then go to a cell which is the cross point of Column W and the Row
defined by the number in cell A100


Many thanks,


V
 
S

Sheeloo

Try
Sub macro()
Set ws = ThisWorkbook.Worksheets("Clients")
ws.Activate
rng = "W" & ws.Range("A100")
ws.Range(rng).Select
End Sub
 
V

Victor Delta

Sheeloo said:
Try
Sub macro()
Set ws = ThisWorkbook.Worksheets("Clients")
ws.Activate
rng = "W" & ws.Range("A100")
ws.Range(rng).Select
End Sub

Many thanks,

V
 
V

Victor Delta

This worked fine until I inserted some additional rows into the spreadsheet
the other day and therefore needed the range formula reference to change to
A105 rather than A100.

Is there a way to improve the formula so this happens automatically in
future?

TIA

V
 
D

Dave Peterson

Select the cell that contains that important information.
Then give it a nice name by typing something like this in the name box (to the
left of the formula bar):
myRowNumber
(remember to hit enter when finish your typing!)

Then change the code to something like:

rng = "W" & ws.Range(myRowNumber).Value
(I like to qualify the property!)
 
V

Victor Delta

Dave Peterson said:
Select the cell that contains that important information.
Then give it a nice name by typing something like this in the name box (to
the
left of the formula bar):
myRowNumber
(remember to hit enter when finish your typing!)

Then change the code to something like:

rng = "W" & ws.Range(myRowNumber).Value
(I like to qualify the property!)

Brilliant! Many thanks,

V
 
V

Victor Delta

Victor Delta said:
Brilliant! Many thanks,

V

Actually, didn't work until I discovered by trial and error that the
inverted commas had to be put back!

Final code therefore: rng = "W" & ws.Range("myRowNumber").Value

V
 

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