LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Passing references

Hi
I am getting 'Subscript out of range' errors with this code.
The project code is to enable me to create new wbooks from each wsheet of
the current wbook. To do this I read the tab names of a wbook as it is
opened. The number of tabs can differ and their names need not be the
standard Sheet1, Sheet2 etc. When required, a procedure is run to determine
the last data row and cell of a wsheet. It is the reference I use that is
creating problems and while it seems to be ok most of the time, it throws an
error if it does not recognise the tab name.

I would appreciate any guidance on this. Hope it makes sense.

Geoff

Code:
On wbook opening:

Dim tabnames() As String
Dim tabname As Variant '''out of desperation

Sub GetTabNames()
ReDim tabnames(1 To ActiveWorkbook.Sheets.Count)
For i = 1 To ActiveWorkbook.Sheets.Count
tabnames(i) = ActiveWorkbook.Sheets(i).Name
Next
End Sub

Then when selecting a chkbox on a form, ask if the tab exists with:
Sub DoesTabExist()
'''test chkbox selection
tab1 = 0
tab2 = 0
tab3 = 0
tabSheetName = 0

For Each tabname In tabnames
If Right(frmBookMaker.ActiveControl.Name, 6) = tabname And LCase(tabname)
= "sheet1" Then
tab1 = 1
Exit For
ElseIf Right(frmBookMaker.ActiveControl.Name, 6) = tabname And
LCase(tabname) = "sheet2" Then
tab2 = 1
Exit For
ElseIf Right(frmBookMaker.ActiveControl.Name, 6) = tabname And
LCase(tabname) = "sheet3" Then
tab3 = 1
Exit For
ElseIf Not frmBookMaker.txtSheetName.Text = "" And
LCase(frmBookMaker.txtSheetName.Text) = LCase(tabname) Then
tabSheetName = 1
End If
Next
End Sub

Then determine if the word xxx exists and other parameters on the wsheet in
question by calling the following sub using - this is where it will error
sometimes

FindxxxCol "Sheet1" '''''''
If foundCol = "" And locatedCol = 0 Then MsgBox "'xxx' does not exist on
this sheet"

Sub FindxxxCol(wsh As String)
With Sheets(wsh) '''''''''' Errors with Subscript out of range
'''clear any old values
foundCol = ""
locatedCol = 0
realLastRow = 0
realLastColumn = 0

'''get real last row and column of data
On Error Resume Next

realLastRow = .Cells.Find("*", .Range("A1"), , , xlByRows, xlPrevious).Row
realLastColumn = .Cells.Find("*", .Range("A1"), , , xlByColumns,
xlPrevious).Column

'''try to find whole Fax on Row 1
foundCol = Split(.Rows(1).Find("xxx", , , xlWhole).Address, "$")(1)

'''if not there look for part xxx on row 1
If foundCol = "" Then foundFax = Split(.Rows(1).Find("xxx", , ,
xlPart).Address, "$")(1)

'''if not there look for whole xxx in rest of data
If foundCol = "" And realLastRow 1 Then
Set tbl = .Range(.Cells(2, 1), .Cells(realLastRow, realLastColumn))
locatedCol = tbl.Find("xxx", , , xlWhole).Row
End If
On Error GoTo 0
End With
End Sub
 
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
How to convert all 3d references to normal references in a workboo Dima Excel Discussion (Misc queries) 6 August 8th 08 12:38 PM
How to convert all 3d references to normal references in a workboo Dima Excel Worksheet Functions 6 August 8th 08 12:38 PM
Help with converting a block of cells with Absolute and mixed references to relative references Vulcan Excel Worksheet Functions 3 December 13th 07 11:43 PM
How to rename references from range names to cell references Abbas Excel Discussion (Misc queries) 1 May 24th 06 06:18 PM
Help with VBA code - passing references to sheets? Rayo K Excel Programming 7 April 20th 06 06:51 PM


All times are GMT +1. The time now is 01:54 AM.

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"