PC Review


Reply
Thread Tools Rate Thread

Cell referencing in Macros

 
 
Rusty_Excelman
Guest
Posts: n/a
 
      6th May 2010
I have automatically created a macro - however would like to modify it so
that it uses data in cell fields rather than hardcoded values in the macro.
For example: sheet selection currerntly is

sheets("wk3").Select

I want to make this more flexible by using a value in cell B2 that contains
the value "wk3". I have attempted unsuccessfully to change the macro as it
errors when I put in the cell reference B2. By doing this it will mean I no
longer need to change the macro each time when the week changes - I just need
to change the value in B2 to the current sheet name.

If the reponse could also include referencing the sheet name for the cell B2
as well that would be great - e.g. Summary!B2 or whatever the answer.

Many thanks

 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      6th May 2010
Try

Sub Macro()
Dim ws As Worksheet
Set ws = Worksheets(Worksheets("Summary").Range("B2").Text)
ws.Select
End Sub


PS: Check out help on named ranges...

--
Jacob (MVP - Excel)


"Rusty_Excelman" wrote:

> I have automatically created a macro - however would like to modify it so
> that it uses data in cell fields rather than hardcoded values in the macro.
> For example: sheet selection currerntly is
>
> sheets("wk3").Select
>
> I want to make this more flexible by using a value in cell B2 that contains
> the value "wk3". I have attempted unsuccessfully to change the macro as it
> errors when I put in the cell reference B2. By doing this it will mean I no
> longer need to change the macro each time when the week changes - I just need
> to change the value in B2 to the current sheet name.
>
> If the reponse could also include referencing the sheet name for the cell B2
> as well that would be great - e.g. Summary!B2 or whatever the answer.
>
> Many thanks
>

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      6th May 2010
Hi,

Something like this

sht = Sheets("Sheet1").Range("B3").Value
Sheets(sht).Select

or is it this

sht = ActiveSheet.Range("B3").Value
Sheets(sht).Select
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Rusty_Excelman" wrote:

> I have automatically created a macro - however would like to modify it so
> that it uses data in cell fields rather than hardcoded values in the macro.
> For example: sheet selection currerntly is
>
> sheets("wk3").Select
>
> I want to make this more flexible by using a value in cell B2 that contains
> the value "wk3". I have attempted unsuccessfully to change the macro as it
> errors when I put in the cell reference B2. By doing this it will mean I no
> longer need to change the macro each time when the week changes - I just need
> to change the value in B2 to the current sheet name.
>
> If the reponse could also include referencing the sheet name for the cell B2
> as well that would be great - e.g. Summary!B2 or whatever the answer.
>
> Many thanks
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cell referencing in macros Rusty_Excelman Microsoft Access Macros 1 6th May 2010 03:29 PM
Cell referencing in Macros Bern Notice Microsoft Excel Programming 5 28th Feb 2009 11:36 PM
Cell referencing, formulas, macros bpotter Microsoft Excel Programming 4 15th Jan 2009 07:55 PM
un-referencing other documents' macros? kill_beast Microsoft Word Document Management 1 16th Sep 2008 06:05 AM
Referencing Macros John Microsoft Excel Programming 4 5th May 2004 11:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:55 AM.