Results 1 to 4 of 4

vba to updata data from one sheet to another

Threaded View

  1. #1
    Registered User
    Join Date
    12-27-2015
    Location
    london
    MS-Off Ver
    ms 2013
    Posts
    2

    vba to updata data from one sheet to another

    Hi all,

    I have the below code which I am trying to use to update data from one sheet to another. The problem is that the location of the relevant columns in the destination file is dynamic and changes (though the name remains the same).

    Could we find something which can remove the restriction of the below colored columns. These columns may not necessarily be in location provided in the code.

    Thanks.

    Sub myUpdate()
    
         'The name of the input worksheet.
         inputSheet = "Source File"
         'The name of the output worksheet.
         outputSheet = "Destination File"
    
         PO_Number_Column_inputSheet = "A"
         Part_Number_Column_inputSheet = "B"
         Status_Column_inputSheet = "C"
         Quantity_Column_inputSheet = "D"
    
         PO_Number_Column_outputSheet = "B"
         Part_Number_Column_outputSheet = "E"
         Status_Column_outputSheet = "AA"
         Quantity_Column_outputSheet = "AC"
    
         'The first row with data in it, not including headers, in the input worksheet.
         firstRow_inputSheet = 2
         'The last row with data is found using the PO Number column A in the input sheet.
         lastRow_inputSheet = Sheets(inputSheet).Range(PO_Number_Column_inputSheet & Rows.Count).End(xlUp).Row
    
         'The first row with data in it, not including headers, in the output worksheet.
         firstRow_outputSheet = 2
         'The last row with data is found using the PO Number column B in the output sheet.
         lastRow_outputSheet = Sheets(outputSheet).Range(PO_Number_Column_outputSheet & Rows.Count).End(xlUp).Row
         
         R_input = firstRow_inputSheet
    
         Do Until R_input > lastRow_inputSheet
    
              PO_Number_Value_inputSheet = Sheets(inputSheet).Range(PO_Number_Column_inputSheet & R_input).Value
              Part_Number_Value_inputSheet = Sheets(inputSheet).Range(Part_Number_Column_inputSheet & R_input).Value
              Status_Value_inputSheet = Sheets(inputSheet).Range(Status_Column_inputSheet & R_input).Value
              Quantity_Value_inputSheet = Sheets(inputSheet).Range(Quantity_Column_inputSheet & R_input).Value
    
              R_output = firstRow_outputSheet
    
              Do Until R_output > lastRow_outputSheet
                   
                   PO_Number_Value_outputSheet = Sheets(outputSheet).Range(PO_Number_Column_outputSheet & R_output).Value
                   Part_Number_Value_outputSheet = Sheets(outputSheet).Range(Part_Number_Column_outputSheet & R_output).Value
                   
                   If PO_Number_Value_inputSheet = PO_Number_Value_outputSheet _
                   And Part_Number_Value_inputSheet = Part_Number_Value_outputSheet Then
                        Sheets(outputSheet).Range(Status_Column_outputSheet & R_output).Value = Status_Value_inputSheet
                        Sheets(outputSheet).Range(Quantity_Column_outputSheet & R_output).Value = Quantity_Value_inputSheet
    
                        Exit Do
                   End If
    
                   R_output = R_output + 1
              Loop
              R_input = R_input + 1
         Loop
    End Sub
    Last edited by FDibbins; 12-27-2015 at 06:43 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Updata new data between sheets by VBA
    By dtaphuong in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-26-2015, 04:59 AM
  2. Macro to updata chart and color 2 line(even and odd series)
    By proxima in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2013, 09:33 AM
  3. As user fills out data sheet, then fill out a results sheet based on data sheet entry
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-13-2012, 03:57 PM
  4. Find and updata data from one sheet to another
    By amarrforever in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-26-2009, 06:19 PM
  5. Referencing and updata master sheet at set intervals
    By freud1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-23-2009, 12:21 AM
  6. [SOLVED] Automatic Updata of Links
    By KG in forum Excel General
    Replies: 0
    Last Post: 03-10-2006, 03:30 PM
  7. macro's run but spread sheet does not updata
    By Morse in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-10-2005, 09:10 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