+ Reply to Thread
Results 1 to 3 of 3

VBA using variable in if statement

  1. #1
    Registered User
    Join Date
    12-18-2013
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    1

    VBA using variable in if statement

    This is my first VBA program and I am trying to use the for loop counter variable inside an if statement as the number of a cell. I think you should get the idea from the code I wrote below:


    Private Sub Worksheet_Change(ByVal Target As Range)
    For i = 3 To 1000
    If Range("Ai") = "Next" Then
    Rows("i").EntireRow.Hidden = True
    Else
    Rows("i").EntireRow.Hidden = False
    End If
    Next i
    End Sub


    What is the correct syntax to do this?

  2. #2
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    330

    Re: VBA using variable in if statement

    take the " marks off of i.
    and range("A" & i) = {or you could use cells(i, 1)}

  3. #3
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: VBA using variable in if statement

    Please Login or Register  to view this content.
    Give Feedback and Click(*)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Trying to do IF statement but variable are too many
    By fsoares22 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-06-2013, 01:04 AM
  2. [SOLVED] Can I use a variable in a IF(,,) statement?
    By Gandalf2524 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-23-2013, 06:54 PM
  3. [SOLVED] For Next Statement with If Statement Reducing Upper Variable
    By Break_Point in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-28-2013, 06:30 PM
  4. Variable IF statement (in VBA)
    By Post Tenebras Lux in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2006, 10:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1