Entry in Hidden and protected Sheet from Data entry Sheet

Rahulkr

Board Regular
Joined
Dec 10, 2019
Messages
66
Office Version
  1. 2010
Platform
  1. Windows
Please help in achieving my task, I have tried to one macro to do some work in this workbook, actually I have prepared this excel for stock and inventory management as per our requirement. In this workbook I am taking data from Data entry sheet and pasting it in Stock out sheet with some remarks, but the content of the remarks is not getting pasted in Stock out sheet and it is pasted as #N/A. Any help is highly appreciated.

Data in the Data entry sheet(HOME) are kept in cell ("E10, E11, E12, E13, E15")

VBA Code:
Sub St_OUT()
Dim r As Range, c As Range
Dim iRow As Long

[B] Set r = Range("E10:E13,E15")[/B]
For Each c In r
If c.Value = "" Then
MsgBox "Please Do Full Entry: " & c.Offset(, -1)
Exit Sub
End If
Next
With Sheets("STOCK OUT")
.Unprotect "123654"
With .ListObjects("Table3")
.ListRows.Add AlwaysInsert:=True
iRow = .DataBodyRange.Rows.Count
.DataBodyRange(iRow, 1).Resize(1, 5).Value = Application.Transpose(r.Value)
End With
.Protect "123654"
Sheets("HOME").Select
[B]Range("E10:E13,E15").ClearContents[/B]
ActiveWorkbook.Save
MsgBox "Data Saved Please Enter New Data !"
End With

End Sub

When I am running the above code it is not pasting the data of the E15 cell value in the STOCK OUT sheet.

Below is the output what I am getting.
DATEENTRY NOITEM NAMEQUANTITYRemarks
01 January 2022BLRSO/1Tissue Roll5#N/A


Any help is highly appreciated. In Home sheet cell no E15 contains some data as remarks, but when running this code it is pasting all data in STOCK OUT Sheet, but only in remarks field the data is pasting as #N/A instead of the data what I need to copy and past in it.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
The problem is with having a non-contiguous range of cells (ie skipping row 14), give this a try.

VBA Code:
    Dim r As Range, c As Range
    Dim iRow As Long
    
    Dim arr() As Variant
    Dim i As Long
    
    Set r = Range("E10:E13,E15")
    ReDim arr(1 To r.Cells.Count)
    i = 0
    
    For Each c In r
        If c.Value = "" Then
            MsgBox "Please Do Full Entry: " & c.Offset(, -1)
            Exit Sub
        End If
        i = i + 1
        arr(i) = c.Value
    Next
    
    With Sheets("STOCK OUT")
        .Unprotect "123654"
        With .ListObjects("Table3")
            .ListRows.Add AlwaysInsert:=True
            iRow = .DataBodyRange.Rows.Count
            .DataBodyRange(iRow, 1).Resize(1, UBound(arr)).Value = arr
        End With
        .Protect "123654"
        Sheets("HOME").Select
        Range("E10:E13,E15").ClearContents
        ActiveWorkbook.Save
        MsgBox "Data Saved Please Enter New Data !"
    End With

End Sub
 
Upvote 0
The problem is with having a non-contiguous range of cells (ie skipping row 14), give this a try.

VBA Code:
    Dim r As Range, c As Range
    Dim iRow As Long
   
    Dim arr() As Variant
    Dim i As Long
   
    Set r = Range("E10:E13,E15")
    ReDim arr(1 To r.Cells.Count)
    i = 0
   
    For Each c In r
        If c.Value = "" Then
            MsgBox "Please Do Full Entry: " & c.Offset(, -1)
            Exit Sub
        End If
        i = i + 1
        arr(i) = c.Value
    Next
   
    With Sheets("STOCK OUT")
        .Unprotect "123654"
        With .ListObjects("Table3")
            .ListRows.Add AlwaysInsert:=True
            iRow = .DataBodyRange.Rows.Count
            .DataBodyRange(iRow, 1).Resize(1, UBound(arr)).Value = arr
        End With
        .Protect "123654"
        Sheets("HOME").Select
        Range("E10:E13,E15").ClearContents
        ActiveWorkbook.Save
        MsgBox "Data Saved Please Enter New Data !"
    End With

End Sub
Thank you very much Alex Blakenburg it worked for me. It's highly appreciated. Thank you very much.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

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