|
-
May 6th, 2005, 11:42 AM
#1
Thread Starter
Junior Member
subscript out of range?
I've got a piece of code that adds the values in cells J12:J30 together and gives the total. In theory this should work:
Set Comm = Worksheets("Sheet2").Range("J12:J50")
showComm = Application.WorksheetFunction.Sum(Comm)
MsgBox showComm
I keep getting a "Subscript out of range" error. Any ideas?
-
May 6th, 2005, 11:53 AM
#2
Re: subscript out of range?
I tried your code with and with data in the range and I got no errors, only a sum with data and a 0 for no data.
Do you have a sheet named "Sheet2"?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 6th, 2005, 11:59 AM
#3
Thread Starter
Junior Member
Re: subscript out of range?
Hi RobbDogg,
Yeah, Ive got a sheet called Sheet2 on the IDE it shows as Sheet2(Pipeline), and out of interest i tried using 'Pipeline' instead of 'Sheet2' but it didnt make a difference. I cant understand it myself, it SHOULD work
-
May 6th, 2005, 12:47 PM
#4
Re: subscript out of range?
Try by index number instead.
VB Code:
Set Comm = Worksheets(1).Range("J12:J50")
'Or
Debug.Print Worksheets.Count
The count will tell you how many indices there are in the workbook. Then use the .Name property to
see which sheet it is referring to.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 6th, 2005, 12:53 PM
#5
Thread Starter
Junior Member
Re: subscript out of range?
changed it to
Set Comm = Worksheets(2).Range("J12:J50")
its working now cheers!
-
May 6th, 2005, 01:06 PM
#6
Re: subscript out of range?
If you Debug.Print Worksheets(2).Name and you get a pipe char at the end, you still may be able to ref the sheet
by its name if you try adding a $ sign after "Sheet2$" in code. The pipe may represent something special of the sheet. Or try renaming
the sheet to something else as a test.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|