In article , Colin Hayes
writes
In article , Trevor Shuttleworth
writes
Colin
looks like you are suffering from "line wrap". The last line should all be
on one line.
Trevor
BTW , do you know if it's possible to hide a tab or tabs in a workbook
from view?
Maybe I could run a macro from a key press to hide / unhide certain
worksheet tabs in a workbook.
Best Wishes
Colin
Hi Trevor
OK that works a treat now. Thanks - I'm grateful for your trouble and
for your expertise. You've really helped me out.
Best Wishes
Colin
Alternatively:
:
Sheets(monthdate).Unprotect Password:="12071956"
destrange.Value = sourceRange.Value
Sheets(monthdate).Protect _
Password:="12071956", _
DrawingObjects:=True, _
Contents:=True, Scenarios:=True
:
Note that the "_" is a line continuation flag. Makes for easier reading and
gets over the problem you have experienced.
So, your code would look like:
Sub copy()
Dim sourceRange As Range
Dim destrange As Range
Dim Lr As Long
Dim monthdate As String
monthdate = Format(Cells(50, 2), "mmmm")
Lr = LastRow(Sheets(monthdate)) + 1
Set sourceRange = Sheets("Receipt ").Rows("50:50")
Set destrange = Sheets(monthdate).Rows(Lr). _
Resize(sourceRange.Rows.Count)
Sheets(monthdate).Unprotect _
Password:="12071956"
destrange.Value = sourceRange.Value
Sheets(monthdate).Protect _
Password:="12071956", _
DrawingObjects:=True, _
Contents:=True, Scenarios:=True
'Print Receipt
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
End Sub
Regards
Trevor
"Colin Hayes" wrote in message
...
In article , Trevor
Shuttleworth
writes
Colin
:
Sheets(monthdate).Unprotect Password:="12071956"
destrange.Value = sourceRange.Value
Sheets(monthdate).Protect Password:="12071956", DrawingObjects:=True,
Contents:=True, Scenarios:=True
:
Regards
Trevor
Hi Trevor
OK thanks for that. I see the logic of what you suggest. I couldn't make
it work however , as I'm getting red errors in the coding. Maybe I'm
putting the code in the wrong place in the routine. You're plainly
better at this than I am - where would you put these lines in the code
so that they protect / unprotect at the right time and don't cause
errors?
Best Wishes
Colin
Sub copy()
Dim sourceRange As Range
Dim destrange As Range
Dim Lr As Long
Dim monthdate As String
monthdate = Format(Cells(50, 2), "mmmm")
Lr = LastRow(Sheets(monthdate)) + 1
Set sourceRange = Sheets("Receipt ").Rows("50:50")
Set destrange = Sheets(monthdate).Rows(Lr). _
Resize(sourceRange.Rows.Count)
destrange.Value = sourceRange.Value
'Print Receipt
ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
End Sub
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
Sub test()
Dim monthdate As String
Dim a As Integer
For a = 1 To 12
monthdate = Format(DateSerial(2003, a, 1), "mmmm")
MsgBox monthdate
Next
End Sub
' Format(Date, "dd-mm-yy")
|