Results 1 to 1 of 1

copy cell values based on conditions to a text file

Threaded View

  1. #1
    Registered User
    Join Date
    07-01-2010
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    8

    copy cell values based on conditions to a text file

    PLEASE! erase this topic, i don't know how it gets duplicated from the original one! thanks!

    copy cell values based on conditions to a text file

    i'm trying to copy two cells values based on a condition from a third cell value to a text document to use to edit a mysql database using the command prompt from phpmyadmin. the text document will include the text as follows for each cell that complies with the condition:

    UPDATE `testdatabase` SET `birthdate` = "2013-07-06" WHERE `name` = "Norman";
    this is part of the macro for conditioning:

        For Each cell In Columns("J").Cells.SpecialCells(xlCellTypeConstants)
            If cell.Value Like "?*@?*.?*" And _
            Cells(cell.Row, "L").Value = "TODAY" And _
            Cells(cell.Row, "O").Value > 0 Then
    this is the part to retrieve the data from specific cells:

    "UPDATE `testdatabase` SET `birthdate` = '" & Cells(cell.Row, "E").Value & "' WHERE `name` = '" & Cells(cell.Row, "M").Value & "';"
    i already can send the data to an email, but it generate an email for each cell, instead i'm looking to include the data on a single text file or maybe on a single email, i just need to copy the output to use it with phpmyadmin:

    Sub SQL_Gen()
        Dim OutApp As Object
        Dim OutMail As Object
        Dim cell As Range
         
        Application.ScreenUpdating = False
        Set OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon
         
        On Error GoTo cleanup
        For Each cell In Columns("J").Cells.SpecialCells(xlCellTypeConstants)
            If cell.Value Like "?*@?*.?*" And _
            Cells(cell.Row, "L").Value = "TODAY" And _
            Cells(cell.Row, "O").Value > 0 Then
                 
                Set OutMail = OutApp.CreateItem(0)
                On Error Resume Next
                With OutMail
    
                    .Body = "UPDATE `testdatabase` SET `birthdate` = '" & Cells(cell.Row, "E").Value & "' WHERE `name` = '" & Cells(cell.Row, "M").Value & "';"
                    .Display 'Or use Display
            End With
                On Error GoTo 0
                Set OutMail = Nothing
            End If
        Next cell
         
    cleanup:
        Set OutApp = Nothing
        Application.ScreenUpdating = True
        
    End Sub
    any help will be appreciate it. thanks!
    Last edited by manteca; 06-07-2013 at 02:53 PM.

Thread Information

Users Browsing this Thread

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

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