Results 1 to 3 of 3

imbedded if statements in a for loop

Threaded View

Dlhans imbedded if statements in a... 11-10-2017, 06:37 PM
alansidman Re: imbedded if statements in... 11-10-2017, 07:23 PM
Dlhans Re: imbedded if statements in... 11-10-2017, 07:52 PM
  1. #1
    Registered User
    Join Date
    11-10-2017
    Location
    US
    MS-Off Ver
    10
    Posts
    2

    imbedded if statements in a for loop

    I have a set of spreadsheets/data that will be downloaded for different files. The data are parced by day, date and time. Different times on different days are required to be treated differently with mathematical functions later. The code I wrote initially shifted some of the data over to new columns, but not all relevant datum. Originally, I had >= in the conditionals.

    the code is here:


    Public Sub Saver_Choice()
    Dim Length As Integer
        Length = Cells(Rows.Count, 1).End(xlUp).Row
        For i = 2 To Length
            If Cells(i, 1).Value = "Saturday" Then
                Cells(i, 4).Value = Cells(i, 4).Value
            ElseIf Cells(i, 1).Value = "Sunday" Then
                Cells(i, 4).Value = Cells(i, 4).Value
            Else
                If Cells(i, 3).Value = "10:00" Then
                    Cells(i, 6).Value = Cells(i, 4).Value
                    Cells(i, 4).Value = 0
                ElseIf Cells(i, 3).Value = "11:00" Then
                    Cells(i, 6).Value = Cells(i, 4).Value
                    Cells(i, 4).Value = 0
                ElseIf Cells(i, 3).Value = "12:00" Then
                    Cells(i, 6).Value = Cells(i, 4).Value
                    Cells(i, 4).Value = 0
                ElseIf Cells(i, 3).Value = "13:00" Then
                    Cells(i, 6).Value = Cells(i, 4).Value
                    Cells(i, 4).Value = 0
                ElseIf Cells(i, 3).Value = "14:00" Then
                    Cells(i, 6).Value = Cells(i, 4).Value
                    Cells(i, 4).Value = 0
                ElseIf Cells(i, 3).Value = "15:00" Then
                    Cells(i, 5).Value = Cells(i, 4).Value
                    Cells(i, 4).Value = 0
                ElseIf Cells(i, 3).Value = "16:00" Then
                    Cells(i, 5).Value = Cells(i, 4).Value
                    Cells(i, 4).Value = 0
                ElseIf Cells(i, 3).Value = "17:00" Then
                    Cells(i, 5).Value = Cells(i, 4).Value
                    Cells(i, 4).Value = 0
                ElseIf Cells(i, 3).Value = "18:00" Then
                    Cells(i, 5).Value = Cells(i, 4).Value
                    Cells(i, 4).Value = 0
                ElseIf Cells(i, 3).Value = "19:00" Then
                    Cells(i, 5).Value = Cells(i, 4).Value
                    Cells(i, 4).Value = 0
                Else
                End If
            End If
        Next i
                
        
        
        
    End Sub

    Any suggestions would be greatly appreciated.

    Thank you.
    Last edited by alansidman; 11-10-2017 at 07:22 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Loop with two statements
    By elmnas in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-25-2016, 08:39 AM
  2. [SOLVED] For loop with mulitple if statements.
    By Petter120 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-03-2014, 02:31 PM
  3. Repeat or Loop VBA Statements
    By zede35 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-03-2014, 03:19 AM
  4. Scrape XML with loop and if-then statements
    By bszen27 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-21-2012, 02:03 PM
  5. VBA Syntax to loop and do if then else statements
    By 1234567890 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-19-2011, 10:39 PM
  6. VBA Do...Loop Statements
    By liseladele in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-24-2006, 06:57 AM
  7. imbedded if statements
    By ksusong in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 09-06-2005, 07:05 PM

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