Hey !!!, I have a code which is running perfectly fine. The code basically is a stock sheet , I have a separate data sheet in the worksheet along with other sheets . Each sheet is named after a stock Item. What i do is i enter my purchase and sales in my data sheet and when i run my macro it posts the same in their respective sheets. Now i would like the data sheet to be in a separate worksheet .
Thanks in Advance.
VBA Code:
Sub Copy_Rows()
Application.ScreenUpdating = False
Dim Cell As Range, R As Range
Set R = Range("H2:H500")
For Each Cell In R
If Cell.Value = "Error" Then
MsgBox "Kindly Check Errors and try again"
Exit Sub
End If
Next Cell
Range("B2:B500").Select
Selection.Replace What:=".", Replacement:="-", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Dim Drange As Range
Dim psheet As Worksheet
Set Drange = Range("A2:E500")
For Each psheet In Worksheets
psheet.unprotect Password:="STOCK"
Next psheet
Sheets("Data Sheet").Activate
Dim i As Long
Dim Lastrow As Long
Lastrow = Sheets("Data Sheet").Cells(Rows.Count, "A").End(xlUp).Row
Dim Lastrowa As Long
For i = 2 To Lastrow
Lastrowa = Sheets(Cells(i, 1).Value).Cells(Rows.Count, "A").End(xlUp).Row + 1
Cells(i, 2).Resize(, 5).Copy Sheets(Cells(i, 1).Value).Rows(Lastrowa)
Next
Drange.ClearContents
For Each psheet In Worksheets
If psheet.Name = "Data Sheet" Then
psheet.unprotect Password:="STOCK"
Else
psheet.Protect Password:="STOCK", AllowFormattingCells:=True, DrawingObjects:=False, Scenarios:= _
True
End If
Next psheet
MsgBox "Data Updated Successfully"
Application.ScreenUpdating = True
End Sub
Thanks in Advance.