nickadeemus2002
New Member
- Joined
- Feb 18, 2004
- Messages
- 41
I need some more help please. I have a simple procedure that asks the user for two inputs, the worksheet name and the range of worksheet, then identifies that blanks and pastes them with blue cells in a new worksheet. I keep getting the run time error when the user inputs the range. How do I resolve this. I've been working on it this morning and I am still analyzing it. Suggestions??
Code:
'This routine will find the blank cells in a
'worksheet and highlight them in a new worksheet.
'
Sub Copy2NewWorksheet()
Dim oOrgRng, oRng As Range
Dim oRngEnd As Range
Dim oSheetName As String
Dim oNewRange, oNewBlankRange As Range
Dim oSht As Worksheet
'Prompt user for Sheet Name
oSheetName = InputBox("Enter Name of Worksheet to inspect.")
'Prompt user for Last Cell
oRngEnd = InputBox("Enter the range of Worksheet to inspect.")
Set oOrgRng = Sheets(oSheetName).Range(oRngEnd)
Set oRng = oOrgRng.SpecialCells(xlCellTypeBlanks)
'if there is no blank cells found, exit this sub directly
If oRng.Count > 0 Then
'Create one new sheet
Set oSht = Sheets.Add
'name new sheet Blanks;
oSht.Name = "blanks"
'select the source range
Sheets(oSheetName).Select
oOrgRng.Select
'perform the copy
Application.CutCopyMode = False
Selection.Copy
'select the new created blanks sheet
Sheets("blanks").Select
'select one cell to star the paste
Call Range("A1").PasteSpecial(xlPasteAll)
Set oNewRange = Selection
Set oNewBlankRange = oNewRange.SpecialCells(xlCellTypeBlanks)
' I set the interior color of these blankcells to blue
oNewBlankRange.Interior.Color = RGB(0, 0, 255)
'Since the contents from the source range has also
'been copied to the new created sheet, clear the source range
oNewRange.ClearContents
End If
End Sub
Code:
'This routine will find the blank cells in a
'worksheet and highlight them in a new worksheet.
'
Sub Copy2NewWorksheet()
Dim oOrgRng, oRng As Range
Dim oRngEnd As Range
Dim oSheetName As String
Dim oNewRange, oNewBlankRange As Range
Dim oSht As Worksheet
'Prompt user for Sheet Name
oSheetName = InputBox("Enter Name of Worksheet to inspect.")
'Prompt user for Last Cell
oRngEnd = InputBox("Enter the range of Worksheet to inspect.")
Set oOrgRng = Sheets(oSheetName).Range(oRngEnd)
Set oRng = oOrgRng.SpecialCells(xlCellTypeBlanks)
'if there is no blank cells found, exit this sub directly
If oRng.Count > 0 Then
'Create one new sheet
Set oSht = Sheets.Add
'name new sheet Blanks;
oSht.Name = "blanks"
'select the source range
Sheets(oSheetName).Select
oOrgRng.Select
'perform the copy
Application.CutCopyMode = False
Selection.Copy
'select the new created blanks sheet
Sheets("blanks").Select
'select one cell to star the paste
Call Range("A1").PasteSpecial(xlPasteAll)
Set oNewRange = Selection
Set oNewBlankRange = oNewRange.SpecialCells(xlCellTypeBlanks)
' I set the interior color of these blankcells to blue
oNewBlankRange.Interior.Color = RGB(0, 0, 255)
'Since the contents from the source range has also
'been copied to the new created sheet, clear the source range
oNewRange.ClearContents
End If
End Sub