Thread: [Solved] For Next Loop cell values
View Single Post
 
Old 03-03-2015, 10:55 AM
grexcelman grexcelman is offline Windows 7 32bit Office 2003
Novice
 
Join Date: Dec 2014
Posts: 21
grexcelman is on a distinguished road
Default

Quote:
Originally Posted by excelledsoftware View Post
I know this is an older post but I cant help but want to help.

I would write what you are doing slightly different but I know it works this way.

Code:
Sub CompareData()
  'Looks at a range and compares it another
  Dim CheckRow As Integer, ws As Worksheet
  
  Set ws = ThisWorkbook.Worksheets("Sheet1")
  
  For CheckRow = 1 To 10
    If ws.Range("A" & CheckRow).Value = ws.Range("F" & CheckRow).Value Then
      'Do whatever you want to do here.
      'Example 1 ws.range("G" & CheckRow).value = "They Match"
    Else
      'Do whatever you want if they dont match or just remove this to say
      'End if
    End If
  Next CheckRow
  
End Sub
This was great. Thanks for replying! I appreciate it as I kept trying to find workarounds for my problem but nothing quite worked as efficiently as I wanted. Your solution should help me. One question, whats the best way to change the sheet name in the 'set ws' line so that I can apply this code on separate sheets?
Reply With Quote