help!

  • Thread starter Thread starter bangity
  • Start date Start date
B

bangity

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
 
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
 
Back
Top