+ Reply to Thread
Results 1 to 2 of 2

Excel VBA to Insert new row as Text format into Protected Sheet1 from Sheet2 User updated

Hybrid View

  1. #1
    Registered User
    Join Date
    08-14-2013
    Location
    Kentucky, United States
    MS-Off Ver
    03,07,10
    Posts
    61

    Exclamation Excel VBA to Insert new row as Text format into Protected Sheet1 from Sheet2 User updated

    Hi All,

    Thank you for taking the time to review this thread! I have been searching for three days for a way to accomplish my need and I have not been able to figure this one out.

    Setup:
    Sheet 1 is Protected to prevent the user from manipulate the data and cause errors. Sheet 1 has existing VBA for upload into a database. Sheet 1 Data does not begin until Row 10 Column C.

    Sheet 2 is Unprotected for user update. Users will be allowed to change existing data or add new data to this sheet. The amount of columns used and the column headings will never change. The amount of Rows would be Dynamic since the user can input New Rows.


    Primary Goal: Data Created or changed in Sheet 2 should be Inserted or updated in the Protected Sheet 1 without allowing the User to change Sheet 1 directly. The change should be enacted upon click of a command button or automatic. (Preferably upon the click of the command button.)

    I have found the following Code but have had issues making both work with what my need is or at all.

    This Code I was not able to Run. I received 2 separate Error codes: "sub or function not defined" & "invalid outside procedure"
    Private Sub copycolumns()
    Dim lastrow As Long, erow As Long
    
    lastrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
    For i = 2 To lastrow
    Sheet1.Cells(i, 1).Copy
    erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
    Sheet1.Paste Destination = Worksheet("Sheet2").Cells(erow, 1)
    
    Sheet1.Cells(i, 3).Copy
    Sheet1.Paste Destination = Worksheet("Sheet2").Cells(erow, 2)
    Sheet1.Cells(i, 4).Copy
    Sheet1.Paste Destination = Worksheet("Sheet2").Cells(erow, 3)
    
    Next i
    
    Application.CutCopyMode = False
    Sheet2.Columns().AutoFit
    Range("A1").Select
    
    End Sub
    This code has potential I would just need to be able to expand the columns copied From B:F until the Row is Null and would need to allow the user to place an "X" in Column A to Define Changes or New data to copy to Sheet 1.
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Target.Address = Range("D4").Address Then
    
            ' Get the last row on our destination sheet (using Sheet2, col A here)...
            Dim intLastRow As Long
            intLastRow = Sheet2.Cells(Sheet2.Rows.Count, "B").End(xlUp).Row
    
            ' Add our value to the next row...
            Sheet2.Cells(intLastRow + 1, "B") = Target.Value
    
        End If
    
    End Sub
    Thanks again for reviewing. I really need the help!

  2. #2
    Forum Contributor
    Join Date
    10-19-2012
    Location
    Omaha, Nebraska USA
    MS-Off Ver
    Excel 2010
    Posts
    249

    Re: Excel VBA to Insert new row as Text format into Protected Sheet1 from Sheet2 User upda

    Hi,

    It doesn't appear the code you posted unprotects Sheet1. Before you run anything on Sheet1, it would need to be unprotected and then you can protect it again after the code has run. The code below is how VBA is used to protect/unprotect a password protected sheet. If the sheet doesn't have a password, just drop the "Password" part:

    Sheets(1).Unprotect Password:="password"
    Hope that provides some guidance,

    Dan

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Use VBA to insert text and format into Sheet2 while in Sheet1
    By Trex1001 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2015, 04:19 PM
  2. Replies: 6
    Last Post: 07-25-2013, 02:58 PM
  3. [SOLVED] Take Data From Column on Sheet1 and Insert Into Next Blank Row on Sheet2 Then Clear Sheet1
    By abutler911 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-09-2013, 06:30 PM
  4. Looking for help to copy a value from sheet1 and insert a new row in Sheet2
    By cdraudt13 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-05-2013, 11:48 PM
  5. [SOLVED] Copy and Paste Entire Row from Sheet1->Sheet2 based on text string match in Sheet1 Row
    By dmlovic in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-17-2012, 08:42 AM
  6. Insert test/valle from sheet1 to sheet2 with a text statement.
    By bpope in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-19-2012, 05:22 AM
  7. Replies: 4
    Last Post: 08-30-2007, 07:14 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1