Hi Experts,
Below is what I've tried to do across multiple worksheets in same workbook (except for Sheet1). The code supposed to insert additional column in each wsheet and put the wsheet name to all rows with data. Then after that need to find strip off the strings "N-" or "AT-" in that first column. It does correctly for inserting the wsheet name but it doesn't do anything on the find & replace strings. And I notice that the highlighted range also not cleared (supposed to be cleared before selecting the whole col A and do the find and replace). But I don't see pop-up error too. Please help to correct my coding below:-
Thank you in advance.
DZ
Below is what I've tried to do across multiple worksheets in same workbook (except for Sheet1). The code supposed to insert additional column in each wsheet and put the wsheet name to all rows with data. Then after that need to find strip off the strings "N-" or "AT-" in that first column. It does correctly for inserting the wsheet name but it doesn't do anything on the find & replace strings. And I notice that the highlighted range also not cleared (supposed to be cleared before selecting the whole col A and do the find and replace). But I don't see pop-up error too. Please help to correct my coding below:-
Code:
Sub InsertSheetNameAll()
Dim LRow As Integer
Dim i As Integer
Dim WS_count As Integer
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If ws.Index > 1 Then
ws.Columns(1).Insert
ws.Cells(1, 1) = "CTT#"
ws.Cells(2, 1) = ws.Name
LRow = ws.Range("B1", ws.Range("B1").End(xlDown)).Rows.Count
'MsgBox LRow
ws.Range("A2").Copy
ws.Range("A3:A" & LRow).PasteSpecial Paste:=xlValues
Columns("A:A").Select
Selection.Replace What:="N-", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="AT-", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("A1").Select
Application.CutCopyMode = False
End If
Application.CutCopyMode = False
Next
End Sub
Thank you in advance.
DZ