jasonb75
Well-known Member
- Joined
- Dec 30, 2008
- Messages
- 15,488
- Office Version
- 365
- Platform
- Windows
Hi all
I'm having a couple of issues with this code, the main one being the line in red, it's meant to insert the text "unknown" into any empty cell in the range covered by the loop, but for some reason it's also changing any cells that were corrected by the previous lines of code where / was replaced with _
The replace code works fine, so I'm at a loss trying to figure out the problem.
The other thing I'm hoping to try and do is to amend the line used to add the new sheets, is it possible for them to be added in alphabetical order by tab name?
Any suggestions? Thanks
I'm having a couple of issues with this code, the main one being the line in red, it's meant to insert the text "unknown" into any empty cell in the range covered by the loop, but for some reason it's also changing any cells that were corrected by the previous lines of code where / was replaced with _
The replace code works fine, so I'm at a loss trying to figure out the problem.
The other thing I'm hoping to try and do is to amend the line used to add the new sheets, is it possible for them to be added in alphabetical order by tab name?
Any suggestions? Thanks
Rich (BB code):
Sub test1()
Application.ScreenUpdating = False
For a = 2 To WorksheetFunction.CountA(Sheet1.Range("A:A"))
Sheet1.Select
TrType = Range("B" & a)
If InStr(TrType, "/") Then
TrType = Replace(Data, "/", "_")
End If
Range("B" & a) = TrType
If Range("B" & a).Value = "" Then Range("B" & a) = "Unknown"
destsht = Range("B" & a).Text
On Error Resume Next
If Not Worksheets(destsht).Name = destsht Then
Worksheets.Add.Name = destsht
Worksheets(destsht).Range("A1:E1").Value = Sheet1.Range("A1:E1").Value
End If
Sheet1.Select
Rows(a).Copy
Sheets(destsht).Select
LR = Cells(Rows.Count, "B").End(xlUp).Row
Rows(LR + 1).Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Next a
End Sub