#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default help!


i created 2 variables string which are o1 and o2. i wanted to store a
value at an offset to o1 and select another sheet and store a value at
the offset of sheet2 in variable o2 but it doesn't work, it only stores
the values from the sheet1 to the 2 variables

count is an int variable

Sheets(1).Select
o = sheet.Offset(count, 0).Value

Sheets(2).Select
o2 = sheet.Offset(count, 2).Value

the problem is itn't store what it suppose to be! someone help please!

here is the whole macro

Code:
--------------------

Sub check()
Dim count As Integer
Dim sheet As Object
Dim he As String
Dim o As String
Dim o2 As String
Set sheet = ActiveCell


If (sheet.Offset(1, 22) = 1) Then
For count = 1 To 150

Sheets(1).Select
o = sheet.Offset(count, 0).Value

Sheets(2).Select
o2 = sheet.Offset(count, 2).Value

If (o < o2) Then
he = MsgBox(o & " is not equal to " & o2 & " at (" & count & ", 0) and (" & count & ", 27)", vbOKCancel + vbInformation, "Error")
Select Case he
Case vbCancel
Exit Sub
End Select
End If
Next
End If
Sheets(1).Select
MsgBox "No Error!", vbOKOnly + vbInformation, "Done!"
End Sub
--------------------


thanks


--
bangity
------------------------------------------------------------------------
bangity's Profile: http://www.excelforum.com/member.php...o&userid=31078
View this thread: http://www.excelforum.com/showthread...hreadid=507525

  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default help!

your problem is you've set your sheet variable equal to the activecell (which
is the active cell on your first sheet at the time you initialized the
variable - as your code executes this variable does not change unless you
change it).

o2 = sheet.Offset(count, 2).Value


You don't often need to select Sheets or Ranges to work with them (and it
speeds up your code if you don't select them).

o2 = Sheets(2).Offset(count, 2).Value

"bangity" wrote:


i created 2 variables string which are o1 and o2. i wanted to store a
value at an offset to o1 and select another sheet and store a value at
the offset of sheet2 in variable o2 but it doesn't work, it only stores
the values from the sheet1 to the 2 variables

count is an int variable

Sheets(1).Select
o = sheet.Offset(count, 0).Value

Sheets(2).Select
o2 = sheet.Offset(count, 2).Value

the problem is itn't store what it suppose to be! someone help please!

here is the whole macro

Code:
--------------------

Sub check()
Dim count As Integer
Dim sheet As Object
Dim he As String
Dim o As String
Dim o2 As String
Set sheet = ActiveCell


If (sheet.Offset(1, 22) = 1) Then
For count = 1 To 150

Sheets(1).Select
o = sheet.Offset(count, 0).Value

Sheets(2).Select
o2 = sheet.Offset(count, 2).Value

If (o < o2) Then
he = MsgBox(o & " is not equal to " & o2 & " at (" & count & ", 0) and (" & count & ", 27)", vbOKCancel + vbInformation, "Error")
Select Case he
Case vbCancel
Exit Sub
End Select
End If
Next
End If
Sheets(1).Select
MsgBox "No Error!", vbOKOnly + vbInformation, "Done!"
End Sub
--------------------


thanks


--
bangity
------------------------------------------------------------------------
bangity's Profile: http://www.excelforum.com/member.php...o&userid=31078
View this thread: http://www.excelforum.com/showthread...hreadid=507525


Reply
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



All times are GMT +1. The time now is 04:18 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"