Marco classing populated cells as blank

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
15,507
Office Version
  1. 365
Platform
  1. 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 :)

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
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Correction to my original post, there was an error in the replace code that I had missed, I changed the variable name used in the original code, but missed one occurence (data changed to TrType). I thought I had tested after the change but looks like I was wrong.

That's now fixed, but I'm still looking to try and sort the sheet order if anyone has ideas for that part.

Thanks :)
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top