Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am using VBA in Microsoft excel in order to export data to a single sheet. I am trying to export data sets from 3

I am using VBA in Microsoft excel in order to export data to a single sheet. I am trying to export data sets from 3 files (three production lines) into a new "Weekly Summary" file. However, the file names change each week to match up with the start date of the week (ex. Line 1 6-26-17). Whenever I try to reference a sheet by having the user select a file by using Application.GetOpenFileName or by having an input box where the user enters the date (ex. user enters date in inputbox "startDate", code searches for 'Workbook("Line 1" & startDate) I keep getting error messages, usually "subscript out of range." Here is my code with the first method I described.

[Code]

Sub weeksumL3()

Dim b As Double Dim c As Double Dim StartDate As String

Dim beforeShift As Variant MsgBox ("Please select this week's data file for line 2") beforeShift = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSM), *.XLSM", Title:="Select File To Be Opened") If beforeShift = False Then Exit Sub

Dim actualShift As Variant MsgBox ("Please select this week's data file for line 3") actualShift = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSM), *.XLSM", Title:="Select File To Be Opened") If actualShift = False Then Exit Sub

Dim weekSum As Variant MsgBox ("Please select this week's Weekly Summary date file") weekSum = Application.GetOpenFilename(Title:="Select File To Be Opened") If weekSum = False Then Exit Sub

b = Range("C1")

Workbooks(beforeShift).Sheets("Data").Range("K4").Copy Workbooks(actualShift).Sheets("Data").Range("K4")

Range("K5") = 0

For i = 1 To b

d = Range("K4") d = d + 1

c = Range("K5") c = c + 1

Workbooks(actualShift).Sheets("Data").Range("A4").Cells(c, 1).Copy Workbooks(weekSum).Sheets("Data").Range("A4").Cells(d, 1) Workbooks(actualShift).Sheets("Data").Range("B4").Cells(c, 1).Copy Workbooks(weekSum).Sheets("Data").Range("B4").Cells(d, 1) Workbooks(actualShift).Sheets("Data").Range("C4").Cells(c, 1).Copy Workbooks(weekSum).Sheets("Data").Range("C4").Cells(d, 1) Workbooks(actualShift).Sheets("Data").Range("D4").Cells(c, 1).Copy Workbooks(weekSum).Sheets("Data").Range("D4").Cells(d, 1) Workbooks(actualShift).Sheets("Data").Range("E4").Cells(c, 1).Copy Workbooks(weekSum).Sheets("Data").Range("E4").Cells(d, 1) Workbooks(actualShift).Sheets("Data").Range("F4").Cells(c, 1).Copy Workbooks(weekSum).Sheets("Data").Range("F4").Cells(d, 1) Workbooks(actualShift).Sheets("Data").Range("G4").Cells(c, 1).Copy Workbooks(weekSum).Sheets("Data").Range("G4").Cells(d, 1) Workbooks(actualShift).Sheets("Data").Range("H4").Cells(c, 1).Copy Workbooks(weekSum).Sheets("Data").Range("H4").Cells(d, 1)

Range("K4") = d Range("K5") = c

Next

Range("K5") = b

End Sub

[End Code]

Any help is greatly appreciated. I can post my other code with the inputbox if that is a better option as well.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

Prove that H2n 1 + n whenever n is a nonnegative integer.

Answered: 1 week ago