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: 333
Default Global Variables and Constants

Hi,

I'm having trouble with this. I have global constant variables and global
variables.

Option Explicit

Public Const CIONameCol As String = "A"
Public Const ServerNameCol As String = "B"
Public Const GroupNameCol As String = "C"
Public Const UserNameCol As String = "D"
Public Const FullNameCol As String = "E"
Public Const UserDomainCol As String = "F"
Public Const GroupTypeCol As String = "G"
Public Const RecertifyCol As String = "H"
Public Const ApprovingManagerCol As String = "I"
Public Const SafetyChkCol As String = "J"

Public wsNew As Worksheet
Public wsOld As Worksheet
Public wbkOld As Workbook
Public wbkNew As Workbook
Public OldJustPath As String
Public NewJustPath As String

I have a procedure which opens the wbkNew, sets it and determines the wbkOld
directory. That procedure then calls this procedure. It errors at the
' MyRow = R2.Find(R1, LookAt:=xlWhole).Row' line telling me 'Object
variable or With block not set. I have tried resetting wbkNew within this
procedure as well as placing the line in a 'with wbkNew - end with. Neither
made any difference. What's wrong?


Sub AllFolderFiles( iCtr, ThisGroupType, ThisUsername, ThisGroupName,
ThisServerName)

Dim TheFile As String
Dim MyPath As String
Dim ThisWkSheet As Worksheet
Dim R1 As Range 'value to find
Dim R2 As Range 'where to look
Dim MyRow As Long
Dim rngCopyTo As Range
Dim rngCopyFrom As Range
Dim OldLusedrow As Long
Dim MatchFound as Boolean
Dim MatchUser As Boolean
Dim MatchGroup As Boolean
Dim MatchServer As Boolean
Dim SafetyCk As String
Dim errLusedrow As Long

MatchFound = False
ChDir OldJustPath
TheFile = Dir("*.xls")

Do While TheFile < ""
Set wbkOld = Workbooks.Open(OldJustPath & "\" & TheFile)
'MsgBox wbkOld.FullName

For Each ThisWkSheet In wbkOld.Worksheets
Set wsOld = ThisWkSheet
'get the last used row on this sheet
OldLusedrow = wsOld.Cells(Rows.Count,
([UserNameCol])).End(xlUp).Row
Debug.Print "wsOld " & wsOld.Name
Debug.Print "ThisWkSheet " & ThisWkSheet.Name
Debug.Print "OldLusedrow " & OldLusedrow
Debug.Print "MyRow " & MyRow

' Debug.Assert RowCtr < 10
If MatchFound = False Then

'check for UserName match

Set R1 =
wbkNew.Sheets(wsNew.Name).Range(([UserNameCol]) & iCtr)
Set R2 =
wbkOld.Sheets(wsOld.Name).Range(([UserNameCol]) & "2:" & ([UserNameCol]) &
OldLusedrow)

On Error GoTo NotFound
MyRow = R2.Find(R1, LookAt:=xlWhole).Row
On Error GoTo 0

Debug.Print "MyRow " & MyRow
MatchUser = True

Set R1 = Nothing
Set R2 = Nothing

'check for groupname match
If ThisGroupName =
wbkOld.Sheets(wsOld.Name).Range(([GroupNameCol]) & MyRow) Then
MatchGroup = True
End If


If ThisGroupType = "Local Group" Then

'check for ServerName match
If ThisServerName =
wbkOld.Sheets(wsOld.Name).Range(([ServerCol]) & MyRow) Then
MatchServer = True
End If

If MatchUser = True Then
If MatchGroup = True Then
If MatchServer = True Then
MatchFound = True

'copy CIOName
Set rngCopyFrom =
wbkOld.Sheets(wsOld.Name).Range(([CIONameCol]) & MyRow)
Set rngCopyTo =
wbkNew.Sheets(wsNew.Name).Range(([CIONameCol]) & iCtr)
rngCopyTo.Value = rngCopyFrom.Value

Set rngCopyTo = Nothing
Set rngCopyFrom = Nothing

'copy FullName
Set rngCopyFrom =
wbkOld.Sheets(wsOld.Name).Range(([FullNameCol]) & MyRow)
Set rngCopyTo =
wbkNew.Sheets(wsNew.Name).Range(([FullNameCol]) & iCtr)
rngCopyTo.Value = rngCopyFrom.Value

Set rngCopyTo = Nothing
Set rngCopyFrom = Nothing

'save SafetyCheck (Where match was
found)
SafetyCk = wbkOld.Name & " " &
wsOld.Name & " Row " & MyRow
Set rngCopyTo =
wbkNew.Sheets(wsNew.Name).Range(([SafetyChkCol]) & iCtr)
rngCopyTo.Value = SafetyCk

Set rngCopyTo = Nothing
Set rngCopyFrom = Nothing

GoTo FoundIt
End If 'MatchServer
MatchServer = False
End If 'MatchGroup
MatchGroup = False
End If 'MatchUser

End If 'Local Group

If ThisGroupType < "Local Group" Then
If MatchUser = True Then
If MatchGroup = True Then
MatchFound = True

'copy CIOName
Set rngCopyFrom =
wbkOld.Sheets(wsOld.Name).Range(([CIONameCol]) & MyRow)
Set rngCopyTo =
wbkNew.Sheets(wsNew.Name).Range(([CIONameCol]) & iCtr)
rngCopyTo.Value = rngCopyFrom.Value

Set rngCopyTo = Nothing
Set rngCopyFrom = Nothing

'copy FullName
Set rngCopyFrom =
wbkOld.Sheets(wsOld.Name).Range(([FullNameCol]) & MyRow)
Set rngCopyTo =
wbkNew.Sheets(wsNew.Name).Range(([FullNameCol]) & iCtr)
rngCopyTo.Value = rngCopyFrom.Value

Set rngCopyTo = Nothing
Set rngCopyFrom = Nothing

'save SafetyCheck (Where match was
found)
SafetyCk = wbkOld.Name & " " &
wsOld.Name & " Row " & MyRow
Set rngCopyTo =
wbkNew.Sheets(wsNew.Name).Range(([SafetyChkCol]) & iCtr)
rngCopyTo.Value = SafetyCk

Set rngCopyTo = Nothing
Set rngCopyFrom = Nothing

GoTo FoundIt
End If 'MatchGroup
MatchGroup = False
End If 'MatchUser
MatchUser = False
End If 'group type not local
End If 'MatchFound = False

NotFound:
Next 'each worksheet

wbkOld.Close
TheFile = Dir

Loop 'Do While

FoundIt:
'reset found indicators
MatchUser = False
MatchGroup = False
MatchServer = False

If MatchFound = False Then

With ThisWorkbook
errLusedrow = shtErrors.Cells(Rows.Count,
([UserNameCol])).End(xlUp).Row + 1
End With

Set rngCopyFrom = wbkNew.Sheets(wsNew.Name).Range(iCtr)
Set rngCopyTo = ThisWorkbook.Sheets("Errors").Range(errLusedrow)
rngCopyTo.Value = rngCopyFrom.Value

Set rngCopyTo = Nothing
Set rngCopyFrom = Nothing
End If

If MatchFound = True Then
MatchFound = False
wbkOld.Close
End If

End Sub

--
Thanks for your help.
Karen53
 
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
Store variables in code just as you can w. constants? Available to read/edit? tskogstrom Excel Programming 3 October 29th 07 10:18 AM
conversion of variables to constants beecher Excel Worksheet Functions 5 November 26th 06 03:55 AM
Global variables Ed Excel Programming 6 November 19th 06 10:55 PM
Global Constants? Bob Excel Programming 2 September 14th 04 02:10 AM
How to set global constants and get path of spreadsh ? wellie Excel Programming 1 July 11th 03 03:06 AM


All times are GMT +1. The time now is 12:35 PM.

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"