I've made some slight changes to your code, see if it works for you..
Sub MISOTTINPUT()
'
' MISOTTINPUT Macro
Dim historyWks As Worksheet
Dim inputWks As Worksheet
Dim nextRow As Long
Dim oCol As Long
Dim myRng As Range
Dim myCopy As Range
Dim myCell As Range
'cells to copy from Input sheet - some contain formulas
Set myCopy = Sheets("Sheet1").Range("B6:R11")
Set inputWks = Worksheets("Sheet2")
Set historyWks = Worksheets("MISUOTWARD")
With historyWks
nextRow = .Cells(.Rows.Count, "E").End(xlUp).Offset(1, 0).Row
End With
With inputWks
Set myRng = myCopy
If Application.CountA(myRng) <> myRng.Cells.Count Then
MsgBox "Hey you must write all the cells!"
Exit Sub
End If
End With
With historyWks
With .Cells(nextRow, "C")
.Value = Now
.NumberFormat = "mm/dd/yyyy hh:mm:ss"
End With
.Cells(nextRow, "kk").Value = Application.UserName
oCol = 4
For Each myCell In myRng.Cells
historyWks.Cells(nextRow, oCol).Value = myCell.Value
oCol = oCol + 1
Next myCell
End With
' Sub Send_Range_Or_Whole_Worksheet_with_MailEnvelope()
'Working in Excel 2002-2013
Dim AWorksheet As Worksheet
Dim Sendrng As Range
Dim rng As Range
On Error GoTo StopMacro
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Fill in the Worksheet/range you want to mail
'Note: if you use one cell it will send the whole worksheet
Set Sendrng = Worksheets("Sheet2").Range("A1:I27")
'Remember the activesheet
Set AWorksheet = ActiveSheet
With Sendrng
' Select the worksheet with the range you want to send
.Parent.Select
'Remember the ActiveCell on that worksheet
Set rng = ActiveCell
'Select the range you want to mail
.Select
' Create the mail and send it
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
' Set the optional introduction field thats adds
' some header text to the email body.
.Introduction = "These are the MIS recorded for the Outward Team"
'.To = "DIBUAEGBOOutwardRemittance@dib.ae"
' .CC = "Yousef.Hindash@dib.ae"
With .Item
' .To = "DIBUAEGBOOutwardRemittance@dib.ae"
.To = "manwar.iqbal@dib.ae"
' .CC = "Yousef.Hindash@dib.ae"
' .BCC = "manwar.iqbal@dib.ae"
' .Subject = "TEST EMAIL - PLEASE IGNORE"
.Subject = "Daily MIS of Number of TT's Processed and the Internal Errors"
.Send
End With
End With
'select the original ActiveCell
rng.Select
End With
'Activate the sheet that was active before you run the macro
AWorksheet.Select
StopMacro:
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
ActiveWorkbook.EnvelopeVisible = False
'clear input cells that contain constants
With inputWks
On Error Resume Next
With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
.ClearContents
Application.GoTo .Cells(1) ', Scroll:=True
End With
On Error GoTo 0
End With
'clear input cells that contain constants
With inputWks
On Error Resume Next
With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
.ClearContents
Application.GoTo .Cells(1) ', Scroll:=True
End With
On Error GoTo 0
End With
Sheets("Sheet2").Range("C4").Select
'Range("C4").Select
Range(Selection, Selection.End(xlDown)).Select
End Sub
I wasn't sure where your mycopy range was so I just did it on sheet1
Bookmarks