+ Reply to Thread
Results 1 to 2 of 2

Copy Column A reference number values only for updated rows

Hybrid View

SierraKilo78 Copy Column A reference... 02-17-2014, 10:21 PM
millz Re: Copy Column A reference... 02-17-2014, 10:31 PM
  1. #1
    Registered User
    Join Date
    12-08-2013
    Location
    Dubai, United Arab Emirates
    MS-Off Ver
    Excel 2010
    Posts
    70

    Copy Column A reference number values only for updated rows

    Hi,

    Need someones valued assistance. I have an workbook (AUTHPbWB) that has a sheet(Replacement) where data is input by end-user. it also has a button(Accept) which stores data in another worksheet based AUTHPbWB cell value D5. The variant data is in range B8-h15 of AUTHPbWM/replacement. When the accept button is clicked, it searches the database sheet for the next available row and inserts the new records. The database sheet has column A that has predefined values that should not change.

    what im looking to do is, on clicking the accept button and when the records update in database, the corresponding values in column A of the database sheet get copied to another worksheet (data) only for the new records updated.

    Spinning my head with this now. tried a few stunts, all failed any help appreciated.

    my current code is

    Option Explicit
    Dim wb As Workbook
    Dim wb1 As Workbook
    Dim wb2 As Workbook
    
    Dim wks As Worksheet
    Dim wks1 As Worksheet
    Dim wks2 As Worksheet
    
    Sub Approved_Click()
    
    Dim myPath As String
        Dim strSubject As String
        Dim strBody As String
        Dim strTo As String
        Dim strCC As String
        Dim Filename As String
        Dim strSheetName As String
        Dim strBookName As String
        Dim r As Long
        Dim c As Range
        
        Dim s As Range
        Dim d As Range
        
        Dim sFileName As String, sSheetName As String
        Const sPath As String = "E:\Project 2013\Office Project 2013\Form Files\"
        
        Set wks1 = ThisWorkbook.Worksheets("Replacement") 'ThisWorkbook.Worksheets("Replacement")
        Set wks2 = ThisWorkbook.Worksheets("Data")
          
        sFileName = wks1.Range("H5").Value
        
        On Error Resume Next
        Set wb1 = Workbooks.Open(sPath & sFileName)
        On Error GoTo 0
        
        If wb1 Is Nothing Then
            Set wb1 = Workbooks.Add
            wb1.SaveAs sPath & sFileName
            ThisWorkbook.Worksheets("ReplTemp").Copy before:=wb1.Sheets(1)
            wb1.Worksheets("ReplTemp").Name = "Replacement"
        End If
        
        Set wks = wb1.Worksheets("Replacement")
           
        For Each c In wks1.Range("B8:B15").SpecialCells(xlCellTypeConstants)
    
            r = wks.Range("B18").End(xlUp).Offset(1, 0).Row
    
            If r > 15 Then
                MsgBox ("Your have availed your monthly quota for application")
                Exit Sub
            End If
            
            c.Resize(1, 6).Copy
            wks.Range("B" & r).PasteSpecial (xlPasteValues)
                    
                wks1.Range("E24").Copy
                wks.Range("H" & r).PasteSpecial (xlPasteValues)
                       
         Next c
           
            Application.CutCopyMode = False
            Application.ScreenUpdating = True

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Copy Column A reference number values only for updated rows

    Assuming your code is working, and assuming wks2 is the correct "Data" sheet, try adding the highlighted code

    Option Explicit
    Dim wb As Workbook
    Dim wb1 As Workbook
    Dim wb2 As Workbook
    
    Dim wks As Worksheet
    Dim wks1 As Worksheet
    Dim wks2 As Worksheet
    
    Sub Approved_Click()
    
    Dim myPath As String
        Dim strSubject As String
        Dim strBody As String
        Dim strTo As String
        Dim strCC As String
        Dim Filename As String
        Dim strSheetName As String
        Dim strBookName As String
        Dim r As Long
        Dim c As Range
        
        Dim s As Range
        Dim d As Range
        
        Dim sFileName As String, sSheetName As String
        Const sPath As String = "E:\Project 2013\Office Project 2013\Form Files\"
        
        Set wks1 = ThisWorkbook.Worksheets("Replacement") 'ThisWorkbook.Worksheets("Replacement")
        Set wks2 = ThisWorkbook.Worksheets("Data")
          
        sFileName = wks1.Range("H5").Value
        
        On Error Resume Next
        Set wb1 = Workbooks.Open(sPath & sFileName)
        On Error GoTo 0
        
        If wb1 Is Nothing Then
            Set wb1 = Workbooks.Add
            wb1.SaveAs sPath & sFileName
            ThisWorkbook.Worksheets("ReplTemp").Copy before:=wb1.Sheets(1)
            wb1.Worksheets("ReplTemp").Name = "Replacement"
        End If
        
        Set wks = wb1.Worksheets("Replacement")
           
        For Each c In wks1.Range("B8:B15").SpecialCells(xlCellTypeConstants)
    
            r = wks.Range("B18").End(xlUp).Offset(1, 0).Row
    
            If r > 15 Then
                MsgBox ("Your have availed your monthly quota for application")
                Exit Sub
            End If
            
            c.Resize(1, 6).Copy
            wks.Range("B" & r).PasteSpecial (xlPasteValues)
                    
                wks1.Range("E24").Copy
                wks.Range("H" & r).PasteSpecial (xlPasteValues)
    
                wks2.Range("A" & rows.count).End(xlUp).Offset(1).Value = wks.Range("A" & r).Value
                       
         Next c
           
            Application.CutCopyMode = False
            Application.ScreenUpdating = True
    多么想要告诉你 我好喜欢你

+ 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. Calculate number of below values reference to particular column
    By mubashar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2014, 04:47 PM
  2. Replies: 1
    Last Post: 03-17-2013, 06:52 AM
  3. Copy formula down rows, but increment column reference
    By purplelily in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-29-2013, 05:38 AM
  4. [SOLVED] macro to copy rows based on number in column
    By amenu in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-03-2012, 06:02 AM
  5. Copy formula down column for a given number of rows
    By dgo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-23-2010, 11:36 AM

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