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!
Bookmarks