+ Reply to Thread
Results 1 to 5 of 5

VBA code to take number from a column put it in another sheet and update to populate value

  1. #1
    Registered User
    Join Date
    01-28-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    VBA code to take number from a column put it in another sheet and update to populate value

    Hi there,
    I've got a big file with a large dataset. One of the sheets works as a screening for the data, so everytime I populate an ID number in say cell C3, the rest of the sheet updates as per the formulas I have in place.
    However, I need to write a code that takes ID numbers one by one from a sheet, populates them into my screening sheet, updates the sheet and saves it.
    Can anyone guide me on what code to use?

    Thank you

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: VBA code to take number from a column put it in another sheet and update to populate v

    yes, but it would be easier if you could provide a sample (non sensitive) on the data along with the desired results

  3. #3
    Registered User
    Join Date
    01-28-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: VBA code to take number from a column put it in another sheet and update to populate v

    Thanks.
    Say in Sheet 1 - Cells A1:A50 have ID numbers.
    Sheet 2: When I write any of the ID numbers in Sheet2!C3 the rest of the sheet updates. That is all fine and automated now.
    The vba code needs to take each number from A1:A50 put it in C3, update sheet and save.

  4. #4
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: VBA code to take number from a column put it in another sheet and update to populate v

    So there are going to be 50 different results and only the last one is going to be saved ..

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-28-2014
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: VBA code to take number from a column put it in another sheet and update to populate v

    Thanks - I managed to get the code up and running however, there is one error. See my code below. The loop should:

    1. Take the "nameFile" (which is the ID number) and put it to "D8"
    2. Then link This workbook F6, F16, F26 to the corresponding values in worksheets "LoniCommentary" of the file specified in namefile "D8".

    My code has everything in place, however, it only links the first file correctly, the corresponding ones are linked to the first ID(Namefile) and not the subsequent ones as specified in D8.

    Additionally, I need to add a command to close the files opened (easy question, I know!)

    Sub singleco()
    '
    ' singleconnection Macro
    '
    Dim i As Integer
    Dim numRows As Integer
    Dim nameFile As String
    Dim ws As Worksheet

    strTemplatePath = "H:\J\VBA summary\RenameTest\" & nameFile
    strTemplateFileName = Dir$(strTemplatePath & "*.xlsx")


    numRows = Application.CountA(ThisWorkbook.Sheets("Sheet2").[A:A])

    For i = 1 To numRows
    nameFile = ThisWorkbook.Sheets("Sheet2").Cells(i, 1).Value

    Workbooks.Open Filename:=strTemplatePath & nameFile, UpdateLinks:=False_

    Set wsChecklist = ActiveWorkbook.Sheets("Checklist")
    Set wsLoniCommentary = ActiveWorkbook.Sheets("LoniCommentary")
    Set wsProperCommentary = ActiveWorkbook.Sheets("PoperCommentary")


    ThisWorkbook.Sheets("Single Connection").[D8].Value = nameFile
    ThisWorkbook.Sheets("Single Connection").Calculate

    [F6].Value = Workbooks(nameFile).Worksheets("LoniCommentary").[D6].Value

    [F16].Value = Workbooks(nameFile).Worksheets("LoniCommentary").[D14].Value

    [F26].Value = Workbooks(nameFile).Worksheets("LoniCommentary").[D22].Value

    ChDir "H:\J\VBA summary"
    ThisWorkbook.SaveAs Filename:=nameFile & ".xlsm"


    Next i

    End Sub



    Thank you very much for your help in advance.

+ 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. [SOLVED] Populate summary sheet with values within specific month column on data sheet...
    By blue91 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-12-2013, 12:11 PM
  2. Replies: 1
    Last Post: 10-22-2012, 01:16 PM
  3. [SOLVED] Sheet Code To Update Automatically
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2012, 09:28 PM
  4. Code to auto populate a relative formula into a column
    By Zyphon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-13-2009, 12:30 PM
  5. Replies: 1
    Last Post: 04-28-2006, 02:20 PM

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