0

I'm in a position where I have to put various repetitive data points into several excel docs and or specific sheets in a mess of a document. As of current there are upwards of 4 documents that all get the exact same information while some of it may be in a different order.

The type of data Inputting

As shown above would basically be the "Master file" to get the job number.

From here we go to another excel that has the various customers (spread through different docs)

Example of the alphabetized customer list

Whom then intern have their own sheets in the docs

Which then to to a customer specific status document

I've been looking for a good way to streamline this process so I'm not having to input these data points 3-4 times every single time a new project comes up.

At this time the best solution I've been able to come up with and test involves manually inputting the data into the first and second excel docs, then from there using a function such as:

='\\File Path\Foldername\AnotherNestedFolderHere\[CUSTOMER LOG B TO I.xls]SHEETNAME'!A1084

Then just modifying the cell info at the end to pull from whatever cell I need at the time for the last two workbooks. Ive been looking all over to try to figure this out from Googling macros to Youtubing VBA but nothing gets close to what I'm trying to do to the best of my understanding.

Edit: I did a little more digging, had an idea with using chatgpt. Well Bings version of it to see about writing something and after about 5 attempts this looks close to what I'm going for but upon testing, it just fails and I'm not 100% sure as to why

Sub CopyData()
Dim wbSource As Workbook
Dim wbTarget As Workbook
Dim wsSource As Worksheet
Dim wsTarget As Worksheet
Dim lastRow As Long
Dim targetFile As Variant
Dim targetSheet As Variant

'Open the source workbook
Set wbSource = ThisWorkbook

'Ask user to select target workbook
targetFile = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*")

'Open the target workbook
Set wbTarget = Workbooks.Open(targetFile)

'Ask user which worksheet to put data onto
targetSheet = InputBox("Enter worksheet name:")

'Set the source worksheet
Set wsSource = wbSource.Worksheets("Sheet1")

'Set the target worksheet
Set wsTarget = wbTarget.Worksheets(targetSheet)

'Find the last row in the source worksheet
lastRow = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row

'Copy the data from column A to I on the last row to the target worksheet
wsSource.Range("A" & lastRow & ":I" & lastRow).Copy wsTarget.Range("A" & wsTarget.Cells(wsTarget.Rows.Count, "A").End(xlUp).Row + 1)

'Increment the next line in column A by one
wsSource.Cells(lastRow + 1, "A").Value = wsSource.Cells(lastRow, "A").Value + 1

'Save and close the target workbook without prompting for changes
wbTarget.Close True

End Sub

Edit: New runtime error

Psichotix
  • 1
  • 2
  • When you say "if fails"? What, precisely, do you mean? Possibilities could be (a) it fails to run (because of a syntax error) (b) it runs but hits a run time error (c) it runs but either does nothing or does something that you didn't want to happen. Rather than using a large language model, have you tried using Excel's macro recorder? – DMM Aug 11 '23 at 19:30
  • I apologize for not specifying what the "it fails" error entailed to correct that it says, "Subscript out of range". for the other half of that No I've not used the macro recorder fully in-depth I've made one macro a few months ago to try to make my job on a specific task a little easier but it wasn't a one size fits all solution. @DMM – Psichotix Aug 11 '23 at 20:00
  • Which line of code? – DMM Aug 11 '23 at 20:02
  • Unfortunately it doesn't say, if it did I might be able to poke and prod see what tweaking may work or say something different, but that's really all I've got. though if i could take a guess at it (assuming i'm doing it correctly through the macros tab) `'Ask user which worksheet to put data onto targetSheet = InputBox("Enter worksheet name:")` right about there is when things mess up, after typing in what sheet I'm trying to have it target. I'm also fully aware that this may be a far more complicated way to try to reach the end result that I'm after. – Psichotix Aug 11 '23 at 20:04
  • When it fails go into the VB Editor. The line that is causing the error will be highlighted. – DMM Aug 11 '23 at 20:16
  • I just tried running it a different way via the VB editor (Just found the little play button) and it gave a runtime error this go around but I didn't notice a highlight. Will add a screenshot in the main bit for reference. I will say I've never done this before so I apologize if I may be misunderstanding something in regards to what you may be referring to. – Psichotix Aug 11 '23 at 20:20

0 Answers0