Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How do I change a variable name based on a sheet name

For example, lets say I have a string variable named strSales, I want to
iterate through the sheets, so when I'm on sheet 1, it'll be strSales1, on
sheet 2 it'll be strSales2, etc.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default How do I change a variable name based on a sheet name

Hi,

Maybe this

Sub nn()
myvar = "strSales"
For x = 1 To Worksheets.Count
myvar = myvar & x

'your code


myvar = "strSales"
Next
End Sub

--
Mike

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


"The Avenger" wrote:

For example, lets say I have a string variable named strSales, I want to
iterate through the sheets, so when I'm on sheet 1, it'll be strSales1, on
sheet 2 it'll be strSales2, etc.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default How do I change a variable name based on a sheet name

I don't believe that will work. It, essentially, changes the myvar to the
value of myvar1, myvar2, etc. What I'm attempting to do is reference a
different variable, based on the sheet name. Sorry for not being clear
earlier.

If I'm on Sheets("George"), I want to reference variable strSalesGeorge, if
on Sheets("Fred"), I want to reference variable strSalesFred, etc.

"Mike H" wrote:

Hi,

Maybe this

Sub nn()
myvar = "strSales"
For x = 1 To Worksheets.Count
myvar = myvar & x

'your code


myvar = "strSales"
Next
End Sub

--
Mike

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


"The Avenger" wrote:

For example, lets say I have a string variable named strSales, I want to
iterate through the sheets, so when I'm on sheet 1, it'll be strSales1, on
sheet 2 it'll be strSales2, etc.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default How do I change a variable name based on a sheet name

Hi,

It will work perfectly based upon your original question. This name includes
the sheet name

Sub nn()
myvar = "strSales"
For x = 1 To Worksheets.Count
myvar = myvar & Sheets(x).name

'your code
MsgBox myvar

myvar = "strSales"
Next
End Sub
--
Mike

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


"The Avenger" wrote:

I don't believe that will work. It, essentially, changes the myvar to the
value of myvar1, myvar2, etc. What I'm attempting to do is reference a
different variable, based on the sheet name. Sorry for not being clear
earlier.

If I'm on Sheets("George"), I want to reference variable strSalesGeorge, if
on Sheets("Fred"), I want to reference variable strSalesFred, etc.

"Mike H" wrote:

Hi,

Maybe this

Sub nn()
myvar = "strSales"
For x = 1 To Worksheets.Count
myvar = myvar & x

'your code


myvar = "strSales"
Next
End Sub

--
Mike

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


"The Avenger" wrote:

For example, lets say I have a string variable named strSales, I want to
iterate through the sheets, so when I'm on sheet 1, it'll be strSales1, on
sheet 2 it'll be strSales2, etc.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default How do I change a variable name based on a sheet name

Cool, ok, thank you

"Mike H" wrote:

Hi,

It will work perfectly based upon your original question. This name includes
the sheet name

Sub nn()
myvar = "strSales"
For x = 1 To Worksheets.Count
myvar = myvar & Sheets(x).name

'your code
MsgBox myvar

myvar = "strSales"
Next
End Sub
--
Mike

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


"The Avenger" wrote:

I don't believe that will work. It, essentially, changes the myvar to the
value of myvar1, myvar2, etc. What I'm attempting to do is reference a
different variable, based on the sheet name. Sorry for not being clear
earlier.

If I'm on Sheets("George"), I want to reference variable strSalesGeorge, if
on Sheets("Fred"), I want to reference variable strSalesFred, etc.

"Mike H" wrote:

Hi,

Maybe this

Sub nn()
myvar = "strSales"
For x = 1 To Worksheets.Count
myvar = myvar & x

'your code


myvar = "strSales"
Next
End Sub

--
Mike

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


"The Avenger" wrote:

For example, lets say I have a string variable named strSales, I want to
iterate through the sheets, so when I'm on sheet 1, it'll be strSales1, on
sheet 2 it'll be strSales2, etc.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
vlookup on different sheet/tab based on stored variable jat Excel Programming 2 October 19th 09 01:49 PM
Change sheet name based on cell value from another sheet tab JDaywalt Excel Programming 2 March 24th 08 03:36 PM
Copy rows to new sheet based on variable cell reference michaelberrier Excel Programming 1 December 26th 06 04:21 PM
How can I change sheet tab color based on cell value in sheet? SCAScot Excel Programming 2 November 23rd 05 09:47 PM
Sheet scroll based on variable Biff Excel Programming 3 September 6th 05 10:30 PM


All times are GMT +1. The time now is 11:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"