Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 30th, 2007, 10:12 AM
Registered User
 
Join Date: Oct 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default question on subscript out of range error?

I am not sure what that means, what causes that, or how to fix it?

When i run my macro, it gives the the "subscript out of range" error!

can anyone help me?

Code:
Sub PnP_Column1_CountRmax()

'   Defines Rmax as a range

Dim Rmax As Range

'   Scans (x,1) for the value of 100

Set Rmax = Range("A:A").Find("100", , xlValues, xlPart)

Call PnP_Column1_FindSemiColon
End Sub



Public Sub PnP_Column1_FindSemiColon()
'   Scans all rows in column 1 for a semicolon (;) and if found, copies that entire row to a seperate workbook.

    Dim rng As Range
    Dim LastRow As Long
    Dim oWB As Workbook
     
    With ActiveSheet
         
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
         
        Set oWB = Workbooks.Add
        Set rng = .Range("A1").Resize(LastRow)
        rng.AutoFilter field:=1, Criteria1:="=;*", Operator:=xlOr, Criteria2:=25
        rng.SpecialCells(xlCellTypeVisible).EntireRow.Copy oWB.Worksheets(1).Range("A1")
        oWB.Worksheets(1).Columns.AutoFit
        rng.AutoFilter
         
        Set rng = Nothing
    End With
    Call Reference_Designator
End Sub

Sub Reference_Designator()

'   wsheet1 and wsheet2 both point to the worksheets where you are looking for info.

'   row 1 tracks what row you are on in the first worksheet

'   row2 treack what row you are on in the second

'   crit1 tracks what your looking for in the first worksheet

'   crit2 tracks what you are looking for in the second.

    Dim wsheet1 As Worksheet, wsheet2 As Worksheet
    Dim row1 As Long, row2 As Long
    Dim crit1 As String, crit2 As String
    row1 = 9
    Set wsheet1 = Workbooks("Testfile2.xls").Worksheets("Sheet1")
    Set wsheet2 = Workbooks("2x2component.xls").Worksheets("2x2component")
    crit1 = 25
    While wsheet1.Range("B" & row1) <> ""
        If wsheet1.Range("A" & row1) = crit1 Then
            row2 = 3
            crit2 = wsheet1.Range("F" & row1)
            While wsheet2.Range("B" & row2) <> ""
                If wsheet2.Range("B" & row2) = crit2 Then
                     'last step
                End If
                row2 = row2 + 1
            Wend
        End If
        row1 = row1 + 1
    Wend
    Call Insert_TrigFunctions
End Sub

Sub Insert_TrigFunctions()

    Dim XC As Long, YC As Long
    '   XC, YC are coordinates of center of IC chip
    Dim XP As Long, YP As Long
    '   XP, YP are coordinates of center of pad relative to the chip
    Dim Rot As Double, DV As Double
    '   Rot is rotation angle, DV is a distance between center of chip to center of pad
    Dim THETA As Double
    '   THETA is the angle of pad relative to center of chip
    Dim XS As Long, YS As Long
    '   XS, YS are XY coordinates of solder dot

    DV = (XP ^ 2 + YP ^ 2) ^ 0.5
    '   Equation to find Vector
    THETA = Pi / 180 * (Atn(YP / XP))
    '   Equation to find THETA angle
    YS = DV * Sin(Pi / 180 * (THETA))
    '   Equation to give YS in radians rather than degrees

        If XP < 0 Then
           THETA = THETA + 180
        End If

End Sub
ya i know i got bits and pieces in there...im not finished yet...still tweaking!
 
Old November 30th, 2007, 10:14 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

The code requires the following Workbooks to be open in Excel

Testfile2.xls with a Sheet called Sheet1
2x2component.xls with a Sheet called 2x2component

Are you sure the above Workbooks are open?

Cheers
Shasur

http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
"Subscript out of range" in acFormPivotChart jilly Access VBA 0 April 23rd, 2008 08:52 PM
Array, Subscript out of range. koss77 VB How-To 4 August 21st, 2006 09:35 AM
Subscript out of range: '[number: 0]' jim_h Classic ASP Professional 0 February 24th, 2006 07:24 PM
Subscript out of range rfrancisco Classic ASP Components 1 February 13th, 2006 08:25 PM
Subscript out of range crmpicco Classic ASP Basics 4 March 22nd, 2005 06:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.