Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Newbie Macro Query - Clearing Variables and Assigning a Variable

Hi all

I have a couple of appallingly easy newbie questions, that I wondere
if somebody could help me with? I have a feeling I'm close, but
can't make it work...

1. I have a macro performing a summation with the results in
variable. It works fine, unless I execute it twice - presumably I nee
a way of clearing the variables after the code has run? What synta
would I need to use for this?

2. I wish to specify a worksheet to activate in the macro by using th
contents of a cell. For example, if I enter "October" in Cell S4,
want the macro to activate the worksheet "October". I've trie
something like the code below, without success. I also though
INDIRECT may help, but I'm unsure how to use it in a macro. Coul
anyone suggest how I might do this?

Dim MonthText

Worksheets("Budget").Activate
Range("S4") = MonthText
Worksheets(MonthText).Activate

Any advice would be much appreciated!

Many thanks

Nei

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Newbie Macro Query - Clearing Variables and Assigning a Variable

1)One easy way:

X=""
once you have used the variable named X

2)
Sub TryThis()
Dim Sht As Worksheet
Dim X As String 'the name of the sheet
'Worksheets("Budget").Activate
X = Range("S4")
'Lcase avoids upper lower... case problems
For Each Sht In ThisWorkbook.Worksheets
If LCase(Sht.Name) = LCase(X) Then
Sht.Activate
Exit For
End If
Next Sht

End Su

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Newbie Macro Query - Clearing Variables and Assigning a Variable

Assuming you have something like the below, initializing the sum variable
should do it.

Public lngSum as Long

Sub ComputeSum()
lngSum = 0
for each cell in Range("A1:A10")
if isnumeric(cell.value) then
lngSum = lngSum + cell.Value
end if
Next
end sub

---------
Worksheets(Worksheets("DATA").Range("B9").Value).A ctivate

--
Regards,
Tom Ogilvy



"Mcneilius " wrote in message
...
Hi all

I have a couple of appallingly easy newbie questions, that I wondered
if somebody could help me with? I have a feeling I'm close, but I
can't make it work...

1. I have a macro performing a summation with the results in a
variable. It works fine, unless I execute it twice - presumably I need
a way of clearing the variables after the code has run? What syntax
would I need to use for this?

2. I wish to specify a worksheet to activate in the macro by using the
contents of a cell. For example, if I enter "October" in Cell S4, I
want the macro to activate the worksheet "October". I've tried
something like the code below, without success. I also thought
INDIRECT may help, but I'm unsure how to use it in a macro. Could
anyone suggest how I might do this?

Dim MonthText

Worksheets("Budget").Activate
Range("S4") = MonthText
Worksheets(MonthText).Activate

Any advice would be much appreciated!

Many thanks

Neil


---
Message posted from http://www.ExcelForum.com/



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Newbie Macro Query - Clearing Variables and Assigning a Variable

Guys, that's perfect - works a treat!

Thank you very much indeed!

Neil


---
Message posted from http://www.ExcelForum.com/

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
Assigning cell values to variables Tim Excel Discussion (Misc queries) 3 June 11th 09 04:30 PM
Assigning a variable Zack Excel Worksheet Functions 3 December 11th 08 07:00 PM
ClearContents Not Clearing Query Sean McPoland[_3_] Excel Programming 1 August 19th 04 07:39 PM
Assigning a row to a variable Todd Excel Programming 4 June 10th 04 06:49 PM
Assigning values from a selected range to individual variables Dr. Schwartz[_3_] Excel Programming 5 January 27th 04 02:27 PM


All times are GMT +1. The time now is 05:46 AM.

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

About Us

"It's about Microsoft Excel"