Вы находитесь на странице: 1из 4

Sub RefineData() ' ' DelRow Macro ' ' Keyboard Shortcut: Ctrl+i ' 'Selection.Copy 'ActiveCell.

Select 'SendKeys "{up}" 'SendKeys "{right}" {left}" 'Selection.Paste 'Selection.EntireRow.Delete Cells(2, Cells(2, Cells(2, Cells(2, Cells(2, Cells(2, Cells(2, Cells(2, Cells(2, Cells(2, Cells(2, Cells(2, 10).Value 11).Value 12).Value 13).Value 14).Value 15).Value 16).Value 17).Value 18).Value 19).Value 20).Value 21).Value = = = = = = = = = = = = "Email Format" "FirstName" "LastName" "Email Id" "firstNameAndEmail" "Phone No" "Company" "Title" "City" "State" "Country" "Updated"

'SendKeys "{down}"

'SendKeys "

Sheets("Sheet1").Select ' Find the last row of data finalRow = Cells(Rows.Count, 1).End(xlUp).Row ' Loop through each row For x = 3 To finalRow ' Decide if to copy based on column D ThisValue = Cells(x, 1).Value AllDataCellEmpty = True 'CHECK if all data cells are EMPTY If (Not IsEmpty(Cells(x, 1).Value)) Or (Not IsEmpty(Cells(x, 2).Value)) Then AllDataCellEmpty = False End If If (IsEmpty(Cells(x, 1).Value)) And (Not IsEmpty(Cells(x, 2).Value)) The n Cells(x + 1, 1).Select Cells(x + 1, 1).Copy Cells(x, 1).Select ActiveSheet.Paste Cells(x + 2, 1).Select Cells(x + 2, 1).Copy Cells(x + 1, 1).Select ActiveSheet.Paste Cells(x + 2, 1).Value = BLANK ThisValue = Cells(x, 1).Value End If If Not AllDataCellEmpty Then If IsEmpty(ThisValue) Then For y = 2 To 7

Cells(x, y).Select Selection.MergeCells = False Next y End If If Not IsEmpty(ThisValue) Then plusString = "+" 'firstChar = Left(ThisValue, 1) If InStr(ThisValue, plusString) = 1 Then Cells(x, 1).Resize(1, 33).Copy Sheets("Sheet1").Select NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1 Cells(x - 1, 15).Select ActiveSheet.Paste Sheets("Sheet1").Select Cells(x, 1).Select Else Sheets("Sheet1").Select Cells(x, 1).Select If Not IsNumeric(ThisValue) Then Dim TempString As String Dim lastName As String Dim firstNameAndEmail As String Dim firstNameAndEmailID As String Dim firstName As String Dim domain As String Dim firstAndFirst As String Dim email As String Dim firstChar As String TempString = ThisValue i = InStr(1, TempString, ",") lastName = Mid(TempString, 1, i - 1) firstNameAndEmail = Mid(TempString, i + 1) 'Get FirstName, LastName i = InStr(1, firstNameAndEmail, "@") firstNameAndEmailID = Mid(firstNameAndEmail, 1, i 1) domain = Mid(firstNameAndEmail, i) Sheets("Sheet1").Select Cells(x, 12).Value = lastName Cells(x, 14).Value = firstNameAndEmail 'Cells(x, 15).Value = firstNameAndEmailID 'Cells(x, 16).Value = domain i = 0 'Extract FirstName i = InStr(firstNameAndEmailID, ".") If Not i = 0 Then '"." found its FirstName.LastName@domain.com firstAndFirst = Mid(firstNameAndEmailID, 1, i 1) firstName = Mid(firstAndFirst, 1, i / 2) Cells(x, 11).Value = firstName email = firstName + "." + lastName + domain

Cells(x, 10).Value = "First.Last@ABC.com" Else i = InStr(LCase(firstNameAndEmailID), LCase(last Name)) If Not i = 0 Then 'its FLastName@domain.com firstAndFirst = Mid(firstNameAndEmailID, 1, i - 1) firstChar = Right(firstAndFirst, 1) firstName = Mid(firstAndFirst, 1, i - 2) Cells(x, 11).Value = firstName email = firstChar + lastName + domain Cells(x, 10).Value = "FLast@ABC.com" Else firstChar = Right(firstNameAndEmailID, 1) i = Len(firstNameAndEmailID) firstName = Mid(firstNameAndEmailID, 1, i / 2) email = firstName + firstChar + domain Cells(x, 10).Value = "FirstL@ABC.com" End If End If Cells(x, 13).Value = Trim(email) End If End If End If End If '-- If AllDataCellEmpty Then -Next x 'FIRST ROUND Cleanup For x = 3 To finalRow ' Decide if to copy based on column D ThisValue = Cells(x, 1).Value If Not IsEmpty(ThisValue) Then plusString = "+" 'firstChar = Left(ThisValue, 1) If InStr(ThisValue, plusString) = 1 Then Sheets("Sheet1").Select Cells(x, 1).Select Selection.EntireRow.Delete End If Else If IsNumeric(ThisValue) Then Sheets("Sheet1").Select Cells(x, 1).Select Selection.EntireRow.Delete Else If IsEmpty(ThisValue) Then Sheets("Sheet1").Select Cells(x, 1).Select Selection.EntireRow.Delete End If End If End If Next x

'SECOND ROUND Cleanup For x = 3 To finalRow ' Decide if to copy based on column D ThisValue = Cells(x, 1).Value If Not IsEmpty(ThisValue) Then plusString = "+" 'firstChar = Left(ThisValue, 1) If InStr(ThisValue, plusString) = 1 Then Sheets("Sheet1").Select Cells(x, 1).Select Selection.EntireRow.Delete End If Else If IsNumeric(ThisValue) Then Sheets("Sheet1").Select Cells(x, 1).Select Selection.EntireRow.Delete Else If IsEmpty(ThisValue) Then Sheets("Sheet1").Select Cells(x, 1).Select Selection.EntireRow.Delete End If End If End If Next x End Sub

Вам также может понравиться