Welcome Guest
Log In | Register )
You last visited January 20, 2017, 8:51 am
All times shown are
Eastern Time (GMT-5:00)

I need help with visual basics for exel

Topic closed. 1 reply. Last post 9 years ago by LottoMining.

Page 1 of 1
New Member
New London CT
United States
Member #57263
December 25, 2007
14 Posts
Posted: January 5, 2008, 10:31 am - IP Logged

Does anyone no how to create a "for/next" loop that will compare specific cells in a specific worksheet. How do I reference the worksheet and the specific cell. The basic program was easy because the info was always in the program. This is gonna be a little more intrinsic I feel. Here's a sample of the normal loop I would use in basic, with the my dilenma about excel.

for a=1 to 5

if a=1 let b="specific worksheet/cell"


then the comparison

if b="specific worksheet/cell" let c=c+1

then dump the result

let "specific workshheet/cell =c

clear c


I think I'm going to have use "range" but perhaps some one can give me a clear macro, thanksWhat?

    LottoMining's avatar - lightbulb
    United States
    Member #48843
    January 11, 2007
    27 Posts
    Posted: January 9, 2008, 3:16 pm - IP Logged

    Is the following code a step in the right direction to compare specific cells across specific worksheets? (I didn't look closely at your logic for a,b, c; only referencing different worksheets/cells)

    Sub Loop5()
    Dim i As Integer, ARef As String, BRef As String, CRef As String, c As Integer

        For i = 1 To 5
            ARef = "A" & CStr(i) 'Cstr() function converts integer to string
            BRef = "B" & CStr(i)  'you may want to change the variable referencing Sheet1
            If Range("SheetX!" & ARef).Value = Range("Sheet1!B" & CStr(i) & "").Value Then
                c = c + 1
            End If
        Debug.Print c
    End Sub