+ Reply to Thread
Results 1 to 4 of 4

do until loop with if statement that applies on different columns (vba)

  1. #1
    Registered User
    Join Date
    08-30-2014
    Location
    london
    MS-Off Ver
    2007
    Posts
    15

    Question do until loop with if statement that applies on different columns (vba)

    Hi,
    I'm scratching my head around what I think "a very simple piece" of code...but I'm a VBA beginner
    I have to perform 2 tasks, and while I've completed the first one, the other is giving me a lot of troubles...

    1st step: clear the content of a range of cells when I switch the xls validation list (yes,no). This works

    Private Sub WorkSheet_Change(ByVal Target As Range)

    If Target.Address = "$E$170" Then Range("$E$178:$E$187").ClearContents

    If Target.Address = "$E$174" Then Range("$E$178:$E$187").ClearContents

    2nd step:
    - I have 2 ranges of value $D$178:$D$187 and $E$178:$E$187
    - the range $D$178:$D$187 can assume the following values: Yes, No, Please select
    - If any value in the range $D$178:$D$187 assume value "Yes" the corresponding value in the range $E$178:$E$187 has to assume value "Yes"
    - If any value in the range $D$178:$D$187 assume value "No" the corresponding value in the range $E$178:$E$187 has to assume value "No"
    - If any value in the range $D$178:$D$187 assume value "Please select" the corresponding value in the range $E$178:$E$187 will result in a validation list "Yes" or "No"

    It's worth saying that the range $E$178:$E$187 has already a xls data validation list set (Yes,No)

    Example
    D180="Yes" then E180="Yes"

    D183="No" then E183="No"

    D185="Please select" then E185= validation list "Yes" or "No"

    I tried as follows but xls crashed

    Set Rng = Range("$E$178:$E$187")
    Range("$D$178").Select
    Do Until Selection.Value = "$D$188"
    If Selection.Value = "Yes" Then
    Rng = "Yes"
    Else
    Rng = "No"
    End If
    Loop

    End Sub

    my assumption is that in all other cases in the range $S$178:$E$187 (i.e. "Please select") the code doesn't apply and I can select "Yes" or "No" in the xls data validation list $E$178:$E$187

    Hope it's clear, I would appreciate any help you can provide!

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: do until loop with if statement that applies on different columns (vba)

    Maybe:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: do until loop with if statement that applies on different columns (vba)

    try this

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-30-2014
    Location
    london
    MS-Off Ver
    2007
    Posts
    15

    Re: do until loop with if statement that applies on different columns (vba)

    thanks mehmetcik, it works!!

+ 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. Loop Across Columns If Blank Cell Loop Down Rows
    By flindy87 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-05-2014, 10:22 AM
  2. [SOLVED] For Next Loop with IF statement inside does not loop
    By roxybethany in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-09-2013, 11:45 AM
  3. Replies: 1
    Last Post: 05-19-2013, 06:40 PM
  4. Trying to Create a Macro that Applies to Entire Columns
    By JEdel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2013, 04:41 PM
  5. [SOLVED] How to specify which cells/columns macro applies to?
    By Workaholic in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-14-2006, 12:55 PM

Tags for this Thread

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