#1
|
|||
|
|||
For Next Loop cell values
I have data in cells A1 through D10 and in column F( F1:F10) I have the averages of each row. I'd like to loop through the range of cells (A1 to D10) and within each row (10 rows) I want to compare the cell value to the corresponding row value in column F(average which is already computed.) Thanks in advance!
I have this so far: For Each c In Worksheets("Sheet1").Range("a1:d10").Cells [code to compare c.value to its corresponding F column value] Next |
#2
|
|||
|
|||
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 |
#3
|
|||
|
|||
Quote:
|
#4
|
|||
|
|||
Pretty easy to do actually. Make sure to dim your other worksheets and give them a variable name such as ws and ws1. I will typically use ws for the worksheet that has the data and then rws for the worksheet that gets the results. When you set something you are telling Excel that you want to reference an object. This is different than setting a string = "Your Name Here" which you would do like so.
Code:
TestString = "Your Name Here" Code:
Dim ws as Worksheet, rws as Worksheet Set ws = ThisWorkbook.Worksheets("Data") Set rws = ThisWorkbook.Worksheets("Results") Code:
Dim ws as Worksheet, rws as Worksheet, wb as Workbook Set wb = ThisWorkbook Set ws = wb.Worksheets("Data") Set rws = wb.Worksheets("Results") Thanks |
Tags |
loop, range |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Convert non-cell input to cell values | TBD | Excel | 3 | 06-09-2014 06:14 AM |
Sum values within a single cell | shabbaranks | Excel | 17 | 05-13-2014 06:47 PM |
How do you loop through an array with some empty values? | omahadivision | Excel Programming | 5 | 11-28-2013 10:49 AM |
change values based on cell | ubns | Excel | 1 | 05-21-2012 06:28 PM |
Automatic, Dependent Cell Values | flackend | Excel | 2 | 08-26-2011 07:01 AM |