I have multiple workbooks and each workbook can have anywhere from 1-20 worksheets and each worksheet is named differently. What I need to be able to do is combine all the worksheets into one master worksheet for each workbook (I don't want to combine workbooks). What I would like to do is create a template that I can use where all I would need to do is change the file name of the workbook and it would automatically combine the worksheets. Any guidance is greatly appreciated!
Posts by AndyD
-
-
Re: Linked Drop Downs Not Populating With Some Characters
ahhh... Thanks!
-
Re: Linked Drop Downs Not Populating With Some Characters
I have my sheet set up the same way as the MatchingListAdvanced.xls example in the Dependent Validation Lists. If I use that exact example and I change the column heading, "Expensive Cars" to "Expensive Cars & Trucks", the second list does not populate, but if I take out the "&" it works . The same thing happens if I put a hyphen in ("Cars-Trucks").
-
I've created a spreadsheet that has two drop down lists. Based on what the user selects from the first list, the second list is populated. It's working great except for the items in the first list that use special character, such as a -, or &. If necessary I can upload a small example of how I have my sheet set up, but I think I found it on this site!
Thanks!
-
Re: Check Pivot Page Field Items
Here is the final code that finds the correct product in the Pivot table, or goes to the next product if it does not exist.
Code
Display MoreSub ImportErrors() Application.ScreenUpdating = False Windows("Product.xls").Activate On Error Resume Next wDate = Range("X1").Value arrValue = 7 arrProduct = 2 'Creates an array with the size based on how many rows contain values Range("A7").Select Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select arrValue = arrValue + 1 Loop arrValue = arrValue - 1 ReDim arrErrorVals(7 To arrValue, 1 To 2) 'Once the size of the array is determined it is filled with the values For intCount = 7 To arrValue arrErrorVals(intCount, 1) = Range("A" & intCount).Address arrErrorVals(intCount, 2) = Range("A" & intCount).Value Next intCount Range("M2").Select Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select arrProduct = arrProduct + 1 Loop arrProduct = arrProduct - 1 ReDim arrProductVals(2 To arrProduct, 1 To 2) For intProduct = 2 To arrProduct arrProductVals(intProduct, 1) = Range("M" & intProduct).Address arrProductVals(intProduct, 2) = Range("M" & intProduct).Value Next intProduct 'Searching for the values and them pulls the call number into the Trends spreadsheet For intProduct = 2 To arrProduct Windows(wDate & "--OtherErrorWeekly.xls").Activate Dim pt As PivotTable Dim PF As PivotField Set pt = ThisWorkbook.Worksheets("Tech Errors for Product").PivotTables("PivotTable36") Set PF = pt.PivotFields("Product") If PIExists(PF, "arrProductVals(intProduct, 2)") Then ActiveSheet.PivotTables("PivotTable36").PivotFields("Product").CurrentPage _ = arrProductVals(intProduct, 2) For intCount = 7 To arrValue Windows(wDate & "--OtherErrorWeekly.xls").Activate Set x = Range("C:C").Find(what:=arrErrorVals(intCount, 2), LookIn:=xlValues) If Not x Is Nothing Then firstAddress = x.Address CurValue = 0 Do x.Activate ActiveCell.Offset(0, 1).Select CurValue = CurValue + Selection.Value Set x = Range("C:C").FindNext(x) Loop While Not x Is Nothing And x.Address <> firstAddress Windows("Product.xls").Activate Sheets("Product").Range("I" & intCount).Select Range("I" & intCount) = CurValue + Selection.Value End If Next intCount End If Next intProduct Application.ScreenUpdating = True End Sub
and here is the Function
CodeFunction PIExists(PF As PivotField, ItemToFind As String) As Boolean Dim pi As PivotItem PIExists = False For Each pi In PF.PivotItems If pi.Name = ItemToFind Then PIExists = True End If Next pi End Function
Thanks again for all your help!
-
Re: Check Pivot Page Field Items
Carl, your explanation makes sense. My thinking when I originally put this together was, since it's pulling data from a previous product, test to make sure the product was changed to the current product before importing the data. It makes a lot more sense to check if the product exists before trying to select it. And best of all… I finally got it working! Thank you for both of your help and suggestions!
-
Re: Macro Pulling Data From A Pivot; Double Counting
Here's the entire code I have so far
Code
Display MoreSub ImportErrors() Application.ScreenUpdating = False Windows("Report.xls").Activate On Error Resume Next wDate = Range("X1").Value arrValue = 7 arrProduct = 2 'Creates an array with the size based on how many rows contain values Range("A7").Select Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select arrValue = arrValue + 1 Loop arrValue = arrValue - 1 ReDim arrErrorVals(7 To arrValue, 1 To 2) 'Once the size of the array is determined it is filled with the values For intCount = 7 To arrValue arrErrorVals(intCount, 1) = Range("A" & intCount).Address arrErrorVals(intCount, 2) = Range("A" & intCount).Value Next intCount 'Creates an array for the products Range("M2").Select Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select arrProduct = arrProduct + 1 Loop arrProduct = arrProduct - 1 ReDim arrProductVals(2 To arrProduct, 1 To 2) For intProduct = 2 To arrProduct arrProductVals(intProduct, 1) = Range("M" & intProduct).Address arrProductVals(intProduct, 2) = Range("M" & intProduct).Value Next intProduct 'Searches for the Product in the Product drop down of the array For intProduct = 2 To arrProduct Windows(wDate & "--OtherErrorWeekly.xls").Activate ActiveSheet.PivotTables("PivotTable36").PivotFields("Product").CurrentPage _ = arrProductVals(intProduct, 2) 'Tests if the Product exists Dim pt As PivotTable Dim PF As PivotField Set pt = ThisWorkbook.Worksheets("Tech Errors for Product").PivotTables("PivotTable36") Set PF = pt.PivotFields("Product") If PIExists(PF, arrProductVals(intProduct, 2)) Then 'Searching for the values and then pulls the call number into the Report spreadsheet For intCount = 7 To arrValue Windows(wDate & "--OtherErrorWeekly.xls").Activate Set x = Range("C:C").Find(what:=arrErrorVals(intCount, 2), LookIn:=xlValues) If Not x Is Nothing Then firstAddress = x.Address CurValue = 0 Do x.Activate ActiveCell.Offset(0, 1).Select CurValue = CurValue + Selection.Value Set x = Range("C:C").FindNext(x) Loop While Not x Is Nothing And x.Address <> firstAddress Windows("Report.xls").Activate Sheets("Product").Range("I" & intCount).Select Range("I" & intCount) = CurValue + Selection.Value End If Next intCount Next intProduct Application.ScreenUpdating = True End Sub
I've also tried substituting you suggestion with a simple if statment:
CodeIf ActiveSheet.PivotTables("PivotTable36").PivotFields("Product") _ = arrProductVals(intProduct, 2) Then
but that does not work either. Thanks again for your help!
-
Re: Macro Pulling Data From A Pivot; Double Counting
Hi Carl. Thanks for the help! I've been trying to get this to work and I'm still can't get it to pull correctly. It doesn't like my code!
-
I have an array set up with values I want to look in a Pivot Field for and then pull data back based on that selection. It works great until there is an item in my array that is not listed in the Pivot Field. Then it pulls the data from the last item again, which skews my results. So my questions is, how can I skip to the next item in an array if it is not listed in the Pivot Field? Here is the section of code I have that I need help with:
CodeActiveSheet.PivotTables("PivotTable36").PivotFields("Product").CurrentPage _ = arrProductVals(intProduct, 2)
I can post more of the code if necessary, but it's fairly long. Thanks for the help!
-
Re: counting quantity of numbers, with conditions
Sorry about that.. I didn't look over my post close enough!
-
Re: counting quantity of numbers, with conditions
I just took the previously posted spreadsheet and modified it.
-
Re: counting quantity of numbers, with conditions
I was able to get it to work like this:
[COLOR="Blue"]=SUMPRODUCT(($A$2:$B$277=1)*(BA$2:$B$277={1,2}))[/COLOR]
-
-
Re: Determine if a Cells value is a Date
Thank you so much for everyones help! I was able to get it working with:
[COLOR="Blue"]=IF(AND(B3>38000,B3<40000), DATEDIF(B3,Today(),"M"), "")[/COLOR] -
Re: counting quantity of numbers, with conditions
Is there an short way to count how many 1's in column A with a matching 1 or 2 in Column B? I know this works
[COLOR="Blue"]=SUMPRODUCT(($A$2:$B$277=1)*(BA$2:$B$277=1))+SUMPRODUCT(($A$2:$B$277=1)*(BA$2:$B$277=2))[/COLOR]
But I would like to get it to something like this:
[COLOR="Blue"]=SUMPRODUCT(($A$2:$B$277=1)*(BA$2:$B$277=AND(1,2)))[/COLOR]
I would think the second way would run a little faster.
-
I'm trying to determine how many months there are between todays date and a date in a cell. The equation works fine except if a date is not in the referenced cell, I will get #Value!. The equation I'm using is:
=DATEDIF(B3,TODAY(),"m")
Is there a way to say, if a cell contains a date, return the number of months, otherwise leave blank. I thought is would be something like the following, but could not get anything to work:
=IF(B3 = DATE, DATEDIF(B3,Today(),"M"), "")
Thanks!
-
Re: Creating Variables with a loop and then loop through them
I ran into the same type of issue with my sheet and counted the number of variables to determine the size of the array
Code
Display MoreRange("A7").Select Do While Not IsEmpty(ActiveCell) ActiveCell.Offset(1, 0).Select arrValue = arrValue + 1 Loop arrValue = arrValue - 1 ReDim arrErrorVals(7 To arrValue, 1 To 2) For intCount = 7 To arrValue arrErrorVals(intCount, 1) = Range("A" & intCount).Address arrErrorVals(intCount, 2) = Range("A" & intCount).Value Next intCount For intCount = 7 To arrValue Windows("Spreadsheet.xls").Activate Set x = Range("C:C").Find(what:=arrErrorVals(intCount, 2), LookIn:=xlValues) If Not x Is Nothing Then firstAddress = x.Address CurValue = 0 Do x.Activate ActiveCell.Offset(0, 1).Select CurValue = CurValue + Selection.Value Set x = Range("C:C").FindNext(x) Loop While Not x Is Nothing And x.Address <> firstAddress Windows("Main.xls").Activate Sheets("Product").Range("I" & intCount) = CurValue End If Next intCount
Hope that helps!
-
Re: Creating Variables with a loop and then loop through them
You are a Genius! I need to spend some time and figure out arrays and how they work. I could probably use arrays in other spreadsheets as well. Thank you so much for your help!
-
Re: Creating Variables with a loop and then loop through them
I created the array and tried to fill it with the correct values. But when the portion of the code that runs to match that info up in another spreadsheet, it's not pulling the right data, so I'm assuming the array isn't filling correctly. I guess I'm fine having all the variables listed like they are. My main concern is getting this portion of the code down to a loop.
Code
Display MorewDate = Range("X1").Value Windows(wDate & "-OtherError.xls").Activate With Range("C:C") Set x = .Find(what:=a7, LookIn:=xlValues) If Not x Is Nothing Then firstAddress = x.Address CurValue = 0 Do x.Activate ActiveCell.Offset(0, 1).Select CurValue = CurValue + Selection.Value Set x = .FindNext(x) Loop While Not x Is Nothing And x.Address <> firstAddress Windows("Folio4X.xls").Activate Sheets("Product").Range("I7") = CurValue End If Windows(wDate & "-OtherError.xls").Activate Set x = .Find(what:=a8, LookIn:=xlValues) If Not x Is Nothing Then firstAddress = x.Address CurValue = 0 Do x.Activate ActiveCell.Offset(0, 1).Select CurValue = CurValue + Selection.Value Set x = .FindNext(x) Loop While Not x Is Nothing And x.Address <> firstAddress Windows("Folio4X.xls").Activate Sheets("Product").Range("I8") = CurValue End If Windows(wDate & "-OtherError.xls").Activate Set x = .Find(what:=a9, LookIn:=xlValues) If Not x Is Nothing Then firstAddress = x.Address CurValue = 0 Do x.Activate ActiveCell.Offset(0, 1).Select CurValue = CurValue + Selection.Value Set x = .FindNext(x) Loop While Not x Is Nothing And x.Address <> firstAddress Windows("Folio4X.xls").Activate Sheets("Product").Range("I9") = CurValue End If
This is only 3 of the 50 finds it goes through. Is there anyway to do a loop to step thought the variables since they are all sequential? Thanks again for your help
-
I have code that creates 50 variables that reference a cell and then uses each of those variables to search for those values in another spreadsheet. I just named the variables accorting to the cell it's referring to in order to make it easier for me to determine it there was a problem pulling data. The code works, but is extremly long. I am looking for a way to shorten it up with loops to create the variables and loop through them, but I am having trouble figuring it out. Any ideas?
Code
Display MoreDim a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, _ a24, a25, a26, a27, a28, a29, a30, a31, a32, a33, a34, a35, a36, a37, a38, a39, _ a40, a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, a51, a52, a53, a54, a55, _ a56 As Variant a7 = Range("A7").Value a8 = Range("A8").Value a9 = Range("A9").Value a10 = Range("A10").Value a11 = Range("A11").Value a12 = Range("A12").Value a13 = Range("A13").Value a14 = Range("A14").Value a15 = Range("A15").Value a16 = Range("A16").Value a17 = Range("A17").Value a18 = Range("A18").Value a19 = Range("A19").Value a20 = Range("A20").Value a21 = Range("A21").Value a22 = Range("A22").Value a23 = Range("A23").Value a24 = Range("A24").Value a25 = Range("A25").Value a26 = Range("A26").Value a27 = Range("A27").Value a28 = Range("A28").Value a29 = Range("A29").Value a30 = Range("A30").Value a31 = Range("A31").Value a32 = Range("A32").Value a33 = Range("A33").Value a34 = Range("A34").Value a35 = Range("A35").Value a36 = Range("A36").Value a37 = Range("A37").Value a38 = Range("A38").Value a39 = Range("A39").Value a40 = Range("A40").Value a41 = Range("A41").Value a42 = Range("A42").Value a43 = Range("A43").Value a44 = Range("A44").Value a45 = Range("A45").Value a46 = Range("A46").Value a47 = Range("A47").Value a48 = Range("A48").Value a49 = Range("A49").Value a50 = Range("A50").Value a51 = Range("A51").Value a52 = Range("A52").Value a53 = Range("A53").Value a54 = Range("A54").Value a55 = Range("A55").Value a56 = Range("A56").Value wDate = Range("X1").Value Windows(wDate & "-OtherError.xls").Activate With Range("C:C") Set x = .Find(what:=a7, LookIn:=xlValues) If Not x Is Nothing Then firstAddress = x.Address CurValue = 0 Do x.Activate ActiveCell.Offset(0, 1).Select CurValue = CurValue + Selection.Value Set x = .FindNext(x) Loop While Not x Is Nothing And x.Address <> firstAddress Windows("Folio4X.xls").Activate Sheets("Product").Range("I7") = CurValue End If Windows(wDate & "-OtherError.xls").Activate Set x = .Find(what:=a8, LookIn:=xlValues) If Not x Is Nothing Then firstAddress = x.Address CurValue = 0 Do x.Activate ActiveCell.Offset(0, 1).Select CurValue = CurValue + Selection.Value Set x = .FindNext(x) Loop While Not x Is Nothing And x.Address <> firstAddress Windows("Folio4X.xls").Activate Sheets("Product").Range("I8") = CurValue End If Windows(wDate & "-OtherError.xls").Activate Set x = .Find(what:=a9, LookIn:=xlValues) If Not x Is Nothing Then firstAddress = x.Address CurValue = 0 Do x.Activate ActiveCell.Offset(0, 1).Select CurValue = CurValue + Selection.Value Set x = .FindNext(x) Loop While Not x Is Nothing And x.Address <> firstAddress Windows("Folio4X.xls").Activate Sheets("Product").Range("I9") = CurValue End If
this is just a portion of it, but you can get the idea of how long this monster is with 50 variables!