+ Reply to Thread
Results 1 to 29 of 29

VBA Script to help moving data from one spreadshee to another in appropriate column and ro

  1. #1
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    VBA Script to help moving data from one spreadshee to another in appropriate column and ro

    I do not know VBS script at all and have had code written here for me before. I apologize in advance that i am asking to get something done with nothing to show.
    I have a 2 files one is file is a month and i will alway have the correct month opened when doing my work and i have the second file that has peoples names that wont change in column A and a location is column B and a count is in Column C.
    I need the name on Counts sheet column A to match Row 1 on 01 - January.xls and then check for the center number on Column B on Counts to match Center Number on O1 - January to copy the data from Count.xlsx Count column C to the correct location on Janauray. Sorry for the confusing information but the spreadsheet i have attached has the information pasted where it belongs.
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    Place this macro in the "Counts" workbook.
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    I am getting an error at
    Set srcWS = ThisWorkbook.Sheets("Data")

    As if it cant find it. Also i did not make this comment did not know how in depth i needed to go. This will be done daily for every day of the month for every month. Not sure if i have to change the file names in this or not each time but that is something simple that can be done (Set desWS = Workbooks("01 - January.xlsx").Sheets("14")). I will always have the correct day open and the correct data to go into that day.

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    Does the Counts workbook contain a sheet named "Data"?

  5. #5
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    The sheet name is Data

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    Is the macro in the Counts workbook?

  7. #7
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    The macro is in Personal macro sheet

  8. #8
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    I have to download this sheet everyday and then run the macro for each day in every month.

  9. #9
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    Try replacing this line of code:
    Please Login or Register  to view this content.
    with this line:
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    That worked perfect. So now i just have to change the name to the correct month and correct day each time correct?
    Thanks

  11. #11
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    Try replacing this line of code:
    Please Login or Register  to view this content.
    with this line:
    Please Login or Register  to view this content.
    This should pick up the month name and month day automatically as long as you run the macro on the correct day and as long as the text in red is always "01".

  12. #12
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    I did not give enough info when i started this. I do this for months 01 - January.xlsx to 12 - December.xlsx all months. Each month has 31 days in it and i have to download the count sheet each day and put the information in manualy. With your macro i dont have to do that but will just have to change the information in the macro for the month and the day. Sorry i did not give enough detail to begin with and thank you for you help.

  13. #13
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    This version of the macro will recognize the workbook name based only on the month so you don't have to change the information in the macro for the month and the day as long as you run it on the correct day meaning that if you want to update the "22" sheet, you would have to run it today because it is the 22nd today.
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    I have a question for you. The above works but i cant run this everyday so it will not work all the time. Is it possible with the original code you provided me if i added a day field in E1 with the day of the month (example 21) would the vbs be able to determine from E1 to put the data in day 21 of the Month that i have open such as 03 - March. Sorry to pester you on this. I already have made what you have given me work but trying to explain to someone else to change the vbs is another thing when i am not around and can do this.
    If this is too much leave it be and i will be fine with what you have already provided it works and i can deal with it
    Thanks again

  15. #15
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    This version will prompt you to enter the day of the month.
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    Not sure why it is erroring on this but here it is

    desWS.Range("C2:L" & lRow).ClearContents

  17. #17
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    error stats method Range of object worksheet failed

  18. #18
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    Make sure that the sheet of the month you entered has the headers and data in columns A:C.

  19. #19
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    I understand i have extra data that is not needed in D and E. I removed that data and it worked you are awesome. One day i will get into doing VBS because it is really useful.

  20. #20
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    Glad it worked out.

  21. #21
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    It did and adding the date to type in was a great idea so thank you. This forum is great for any help.

  22. #22
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    My pleasure.

  23. #23
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    So i have been using this for a week now and it has been fine and i have not changed anything but now it is giving me an error at

    lRow = desWS.Range("A" & Rows.Count).End(xlUp).Row - 1

    error that comes up is Object variable or With block variable not set. Any idea what could cause this.

  24. #24
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    after doing a little testing the macro works in 02 - February but does not in 01 - January.xlsx. Not sure why but i just ended up taking what i needed for Jan and putting it in Feb then copying that data over to Jan. Made it work but not sure why it does not work in 01 - January.xlsx.

  25. #25
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    Can you post the files that are not working for you?

  26. #26
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    Here is the script you created and it is in with another macro. Was trying to do this for any day in Jan but not working. The files attached are for day 31.
    This worked in Feb but now it is not working at all trying to figure out what i am missing. (Update on this i tried this morning and Feb is working but it did not work first thing it failed). Not sure if this is more like an excel issue not the program because it is working now.

    Application.ScreenUpdating = False
    Dim WB As Workbook, srcWS As Worksheet, desWS As Worksheet, lRow As Long
    Dim v As Variant, v2 As Variant, i As Long, rName As Range, x As Variant, wsName As String
    Set srcWS = Workbooks("Radiology Daily Study Count Admin.csv").Sheets("Radiology Daily Study Count Adm")
    wsName = InputBox("Please enter the day of the month to update.")
    If wsName = "" Then Exit Sub
    For Each WB In Workbooks
    If WB.Name Like "*" & MonthName(Month(Date)) & "*" Then
    Set desWS = Workbooks(WB.Name).Sheets(wsName)
    Exit For
    End If
    Next WB
    lRow = desWS.Range("A" & Rows.Count).End(xlUp).Row - 1
    desWS.Range("C2:L" & lRow).ClearContents
    v = srcWS.Range("A4", srcWS.Range("A" & Rows.Count).End(xlUp)).Resize(, 3).Value
    v2 = desWS.Range("A2", desWS.Range("A" & Rows.Count).End(xlUp)).Value
    For i = LBound(v) To UBound(v)
    Set rName = desWS.Rows(1).Find(v(i, 1), LookIn:=xlValues, lookat:=xlWhole)
    x = Application.Match(v(i, 2), v2, 0)
    If Not IsError(x) Then
    desWS.Cells(x + 1, rName.Column) = v(i, 3)
    End If
    Next i
    Application.ScreenUpdating = True
    Attached Files Attached Files
    Last edited by phealey; 02-05-2024 at 10:37 AM.

  27. #27
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    Here is the script you created and it is in with another macro
    What other macro are you using? Please post the code in the other macro and remember to use code tags whenever you are posting any code. In which workbook are the macros?

  28. #28
    Registered User
    Join Date
    03-03-2015
    Location
    United States
    MS-Off Ver
    2010
    Posts
    18

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    It is not another macro it is just editing the way the excel looks just deleting field and clearing content. Then it run the script you created for me. The macros are in the personal book. all seems to be working now though so no changes are needed. Think it was a excel issue.

  29. #29
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA Script to help moving data from one spreadshee to another in appropriate column an

    Glad it worked out.

+ 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. Replies: 4
    Last Post: 05-22-2020, 04:01 AM
  2. [SOLVED] moving mismatched data from column to corresponding row with target data in same column
    By Didomenicon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2014, 01:16 AM
  3. Replies: 1
    Last Post: 01-22-2013, 06:53 PM
  4. Macro/Script for Moving Groups of Data in to Separate Columns
    By JustinSxcel in forum Excel Programming / VBA / Macros
    Replies: 23
    Last Post: 07-05-2012, 01:56 AM
  5. Replies: 5
    Last Post: 02-07-2012, 04:55 PM
  6. Moving data between sheets:magazine library spreadshee
    By rxwillow in forum Excel General
    Replies: 4
    Last Post: 04-17-2008, 09:04 PM
  7. Moving to and from lines within a Script (goto line)
    By realniceguy5000 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-11-2008, 06:28 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