Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 2nd, 2009, 05:35 AM
TMD TMD is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 1 TMD User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 41 sec
Reputation Power: 0
Excel Macro Code Help

Hi there,

I'm trying to make a very simple excel macro but I'm struggling with range variables. This is the code i'm using:
vb Code:
Original - vb Code
  1. Sub Process_CheckBox()
  2. '
  3. ' Final Macro
  4.  
  5. '
  6.     Dim cBox As CheckBox
  7.     Dim LRow As Integer
  8.     Dim LRange As String
  9.     Dim Rone As String
  10.     Dim Rtwo As String
  11.    
  12.  
  13.     LName = Application.Caller
  14.     Set cBox = ActiveSheet.CheckBoxes(LName)
  15.  
  16.     'Find row that checkbox resides in
  17.     LRow = cBox.TopLeftCell.Row
  18.     LRange = "H" & CStr(LRow)
  19.     Rone = "B" & CStr(LRow)
  20.     Rtwo = "H" & CStr(LRow)
  21.    
  22.    
  23.  
  24.     'Change date in column B, if checkbox is checked
  25.     If cBox.Value > 0 Then
  26.         Range("B4:H4").Select
  27.     With Selection.Interior
  28.         .ColorIndex = 3
  29.         .Pattern = xlSolid
  30.     End With
  31.     'Clear date in column B, if checkbox is unchecked
  32.     Else
  33.         Range("B4:H4").Select
  34.     Range("B4:H4").Activate
  35.     Selection.Interior.ColorIndex = xlNone
  36.     End If
  37.  
  38. End Sub
The range never change, just the row number. I thought i could have two variables, Rone and Rtwo, make then into references like B5 and H5 and then use them like: Range("Rone:Rtwo").Select

but that doesn't work.

where am i going wrong?

Moderator's Note: Syntax highlighting added by Nilpo

Last edited by Nilpo : July 16th, 2009 at 08:28 AM.

Reply With Quote
  #2  
Old July 2nd, 2009, 05:39 AM
sync_or_swim's Avatar
sync_or_swim sync_or_swim is offline
Moderator
Click here for more information.
 
Join Date: Mar 2006
Location: South Wales
Posts: 3,461 sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level)sync_or_swim User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Day 16 h 50 m 26 sec
Reputation Power: 1806
--> Moved to VB Forum

Hi,

I've not had any experience with this but I would imagine that you need to concatenate your values in some way, try something like this:
Code:
Range(Rone & ":" & Rtwo).Select

Or you may need to surround the values with double quotes:
Code:
Range(""" & Rone & ":" & Rtwo & """).Select
Comments on this post
June7 agrees!

Reply With Quote
  #3  
Old July 16th, 2009, 04:09 AM
June7 June7 is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2009
Location: The Great Land
Posts: 536 June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 13 h 58 m 7 sec
Reputation Power: 124
Yes, you will need to concatenate. Here are some examples of using the Range, Cells, Columns objects/properties:
This one uses Range with a variable for the bottom row of range
Code:
'Sort records on Results sheet so they will be in Date then Point then LabNum order for the GEOReport
Worksheets("Results").Range("3:" & intResults + 2).Sort _
    Key1:=Worksheets("Results").Range("AO3"), Order1:=xlAscending, _
    Key2:=Worksheets("Results").Range("A3"), Order2:=xlAscending, _
    Key3:=Worksheets("Results").Range("B3"), Order3:=xlAscending, _
    Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
This one uses Cells with variable for the row and index for the column. Am considering changing this to use Range.
Code:
With Worksheets("Results")
.Cells(intNCount, 1).Value = rsData.Fields("SampledFrom")
.... about 40 similar lines
End With
Here is Columns
Code:
xlApp.Worksheets("Sheet1").Columns("B").ColumnWidth = 12

Last edited by June7 : July 16th, 2009 at 04:29 AM.

Reply With Quote
  #4  
Old July 16th, 2009, 08:29 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 1,880 Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)Nilpo User rank is General (90000 - 100000 Reputation Level)  Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1Folding Points: 214558 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 1 Week 2 Days 8 h 47 m 8 sec
Reputation Power: 967
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo Send a message via XFire to Nilpo
Facebook MySpace Orkut
Thread moved to Windows Scripting.
__________________
Don't like me? Click it.

Scripting problems? Windows questions? Ask the Windows Guru!

Stay up to date with all of my latest content. Follow me on Twitter!

Help us help you! Post your exact error message with these easy tips!

Reply With Quote
Reply

Viewing: ASP Free ForumsSystem AdministrationWindows Scripting > Excel Macro Code Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek