jimmyfinch
Programmer
Hi, is there a macro to move rows to the top of a worksheet that have certain chars like dashes, perods, commas etc. and change the font colour to red?
Many thanks,
Jim
Many thanks,
Jim
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
If Instr(Range("A1"),"/") <> 0 Then
' Do Your Stuff
End IF
Sub FindSpecChar()
Dim X As Long
For X = 3 To 65536
With Range("A" & X)
If InStr(.Value, "/") <> 0 Then
RunMyRecordedProcess
ElseIf InStr(.Value, "-") <> 0 Then
RunMyRecordedProcess
ElseIf InStr(.Value, "?") <> 0 Then
RunMyRecordedProcess
ElseIf InStr(.Value, "\") <> 0 Then
RunMyRecordedProcess
End With
End With
Next
End Sub
Sub RunMyRecordedProcess()
MsgBox "this is where you move the rows"
End Sub
How does it move the rows to the top?
Sub FindSpecChar()
Dim X As Long
'For X = 1 To 65536
For X = 1 To 1000
'MsgBox "A" & X
With Range("A" & X).Select
If InStr(ActiveCell.Text, "/") <> 0 Then
'RunMyRecordedProcess
'MsgBox "/" & X
Range("A" & X).Select
Selection.Font.ColorIndex = 3
ElseIf InStr(ActiveCell.Text, "-") <> 0 Then
'RunMyRecordedProcess
'MsgBox "-" & X
Range("A" & X).Select
Selection.Font.ColorIndex = 3
ElseIf InStr(ActiveCell.Text, "?") <> 0 Then
'RunMyRecordedProcess
'MsgBox "?" & X
Range("A" & X).Select
Selection.Font.ColorIndex = 3
ElseIf InStr(ActiveCell.Text, "\") <> 0 Then
'RunMyRecordedProcess
'MsgBox "\" & X
Range("A" & X).Select
Selection.Font.ColorIndex = 3
End If
End With
Next
End Sub
Sub FindSpecChar()
Dim X As Long
For X = 1 To 1000
With Range("A" & X)
If InStr(.Value, "/") <> 0 Then
RunMyRecordedProcess X
ElseIf InStr(.Value, "-") <> 0 Then
RunMyRecordedProcess X
ElseIf InStr(.Value, "?") <> 0 Then
RunMyRecordedProcess X
ElseIf InStr(.Value, "\") <> 0 Then
RunMyRecordedProcess X
End If
End With
Next
End Sub
Sub RunMyRecordedProcess(LRow As Long)
Range("A" & LRow).Font.ColorIndex = 3
If LRow > 1 Then
Rows(LRow).Cut
Rows("1:1").Insert Shift:=xlDown
End If
End Sub
Sub DeleteUnused()
Dim myLastRow As Long
Dim myLastCol As Long
Dim wks As Worksheet
Dim dummyRng As Range
For Each wks In ActiveWorkbook.Worksheets
With wks
myLastRow = 0
myLastCol = 0
Set dummyRng = .UsedRange
On Error Resume Next
myLastRow = _
.Cells.Find("*", after:=.Cells(1), _
LookIn:=xlFormulas, lookat:=xlWhole, _
searchdirection:=xlPrevious, _
searchorder:=xlByRows).Row
myLastCol = _
.Cells.Find("*", after:=.Cells(1), _
LookIn:=xlFormulas, lookat:=xlWhole, _
searchdirection:=xlPrevious, _
searchorder:=xlByColumns).Column
On Error GoTo 0
If myLastRow * myLastCol = 0 Then
.Columns.Delete
Else
.Range(.Cells(myLastRow + 1, 1), _
.Cells(.Rows.Count, 1)).EntireRow.Delete
.Range(.Cells(1, myLastCol + 1), _
.Cells(1, .Columns.Count)).EntireColumn.Delete
End If
End With
Next wks
CorrectFormat
End Sub
Sub CorrectFormat()
'Stops the screen from flickering
Application.ScreenUpdating = False
' Removing borders, setting font.
MsgBox "Removing borders, setting font."
Cells.Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Selection.Font.Bold = False
' Set format of Column A to Text.
MsgBox "Set format of Column A to Text."
'Columns("A:A").Select
Selection.NumberFormat = "@"
' Removing Invalid Characters - Periods, Commas, Spaces.
MsgBox "Removing Invalid Characters - Periods, Commas, Hyphens, Spaces."
Cells.Replace What:=".", Replacement:="", lookat:=xlPart, searchorder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:=",", Replacement:="", lookat:=xlPart, searchorder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:="-", Replacement:="", lookat:=xlPart, searchorder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Cells.Replace What:=" ", Replacement:="", lookat:=xlPart, searchorder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
'MsgBox "Detecting Slashes, Dashes, Brackets"
Dim X As Long
Dim Y As Long
Y = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
'MsgBox Y
For X = 1 To Y
' Delete Rows where Quantity = 0 or NULL
MsgBox "Delete Rows where Quantity = 0 or NULL"
End With
With Range("A" & X).Select
If InStr(ActiveCell.Text, "/") Or InStr(ActiveCell.Text, "\") <> 0 Then
'RunMyRecordedProcess
Selection.Font.ColorIndex = 3
Range("C" & X).Value = "1"
' ElseIf InStr(ActiveCell.Text, "-") <> 0 Then
'RunMyRecordedProcess
' Selection.Font.ColorIndex = 3
' Range("C" & X).Value = "2"
ElseIf InStr(ActiveCell.Text, "(") Or InStr(ActiveCell.Text, ")") <> 0 Then
'RunMyRecordedProcess
Selection.Font.ColorIndex = 3
Range("C" & X).Value = "3"
End If
End With
Next
' Sort Data by Column C.
MsgBox "Sort Data by Column C."
Columns("A:C").Select
Selection.Sort Key1:=Range("C1"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
' Delete Column C
Columns("C:C").Select
Selection.Delete Shift:=xlToLeft
End Sub