+ Reply to Thread
Results 1 to 3 of 3

VBA If, Then, Else Loop Until

Hybrid View

  1. #1
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    11

    VBA If, Then, Else Loop Until

    Hi,

    I would appreciate help on the following. I've attached an XLS - I'm trying to learn this concept to use for a plethora of other macros

    The two columns I want to populate are M and N

    My mindset is to start with C3... IF(C3>0,offset(c3,-1,0),[if its = 0 then it should just move to D3 and repeat until the cell value >0])

    Then once there's an answer it will begin looping to the next row 4 and repeat the process until column B is empty

    Really appreciate it. Thank you.

    VBA_1.xlsx

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: VBA If, Then, Else Loop Until

    Hi, AMJ,

    what shall go into Columns M and N? If you attach a sample it would be nice to see the data before and after to know what to code for.

    Edit:
    maybe I figured put what you are after.

    Sub EF1021330()
    
    Dim lngCol  As Long
    Dim lngRC   As Long
    Dim blnSkip As Boolean
    
    lngCol = 3
    For lngRC = 3 To Range("B" & Rows.Count).End(xlUp).Row
      Do
        If Cells(lngRC, lngCol).Value > 0 Then
          If blnSkip = False Then
            Cells(lngRC, "M").Value = Cells(2, lngCol).Value
          End If
          blnSkip = True
        Else
          If blnSkip = True Then
            Cells(lngRC, "N").Value = Cells(2, lngCol - 1).Value
          End If
          blnSkip = False
        End If
        lngCol = lngCol + 1
      Loop While lngCol < 13
      lngCol = 3
    Next lngRC
    
    End Sub
    Ciao,
    Holger
    Last edited by HaHoBe; 06-30-2014 at 12:09 AM. Reason: added code
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    01-22-2013
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: VBA If, Then, Else Loop Until

    Holger, Thank you so much! This is exactly what I am looking for.

+ 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. HOW TO: Pause loop, fix error on a popup UserForm, continue loop
    By AndyMachin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-19-2014, 04:37 PM
  2. Loop through multiple files and call macros (but unable to loop)
    By ryanpetersen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-23-2014, 12:04 PM
  3. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  4. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM
  5. Replies: 0
    Last Post: 07-20-2010, 11:42 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