Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #61  
Old 04-16-2015, 10:13 AM
ksigcajun ksigcajun is offline Creating multiple spreadsheets based on text Windows 7 64bit Creating multiple spreadsheets based on text Office 2010 64bit
Advanced Beginner
Creating multiple spreadsheets based on text
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default

Update:

Its now populating the sheets, but it does not distinguish between years. It will populate the sheet with data from all years, even if I choose '2015'.

PHP Code:
Private Sub UserForm_Initialize()
With ComboBox1
.AddItem "2015"
.AddItem "2016"
.AddItem "2017"
.AddItem "2018"
End With
Lbl_exit
:
Exit 
Sub
End Sub 
PHP Code:
Private Sub CommandButton1_Click()
Application.ScreenUpdating False
Application
.DisplayAlerts False
Dim Fpass 
As Boolean
Dim i 
As Long
Dim lrow 
As Long
Dim Rlrow 
As Long
Dim ws 
As Worksheet
Dim AllCells 
As Range
Dim cell 
As RangeRng As Range
Dim Dcell 
As Range
Dim NoDupes 
As New Collection
Dim wBook 
As Workbook
Dim Drng 
As Range
Dim Myval 
As Integer
Dim VenFile 
As String
Dim MyPath 
As String
Dim TempPath 
As String '' for Template
Dim Newwb 
As String '' for New Vendor
Dim Twb 
As Workbook
Dim Thswb 
As Workbook
Set Thswb 
ActiveWorkbook
Fpass 
False
MyPath 
ThisWorkbook.Path ''' set your path using the workbook path
TempPath = "C:\Users\thomasb\Desktop\Test\Macro\Vendor Template1.xltx" ''' 
you need to update this to your path
                                                                    
'' be sure it's in the same path as the Data workbook
Newwb = "C:\Users\thomasb\Desktop\Test\Macro\" ''' 
you need to update this to your path
                                                                    
'' be sure it's in the same path as the Data workbook
Newwb = "C:\Users\thomasb\Desktop\Test\Macro\"
Set ws = Sheets("Sheet1") '''' change to your sheet name in data file
With ws
    lrow = .Range("A65536").End(xlUp).Row
    Set AllCells = Range("A2:A" & lrow)
    ''' 
We will load the filter with out duplicate vendors''
    
For Each cell In AllCells
        On Error Resume Next
        NoDupes
.Add cell.ValueCStr(cell.Value)
    
Next cell
        On Error 
GoTo 0
        
For Each Item In NoDupes
        
'''''set filter for vendor '''
            
Range("A1:F1").Select
            Selection
.AutoFilter
            With Selection
                
.AutoFilter field:=1Criteria1:=Item '' this set the filtered data for the value
            End With
            Set Rng 
ActiveSheet.AutoFilter.Range
            
'' make sure you have more than 1 row to copy ''
            
Myval Range("A2:A" lrow).SpecialCells(xlCellTypeVisible).Count
            
If Myval >= "1" Then
            
'''' First open Vendor workbook then populate the data to Sheet1 and Sheet2 '''
                Set Drng = Range("A2", Range("A65536").End(xlUp)).SpecialCells(xlCellTypeVisible)


                On Error Resume Next
                Workbooks.Open Filename:=MyPath & "\" & Item & ".xlsx", UpdateLinks:=0
                If Err = "1004" Then '' this will add New Vendor workbook and populate
                    Fpass = False
                    Workbooks.Open Filename:=TempPath, UpdateLinks:=0, Editable:=True
                        ActiveWorkbook.SaveAs Filename:=Newwb & Item & ".xlsx", FileFormat:=xlOpenXMLWorkbook _
                            , CreateBackup:=False
                    For Each Dcell In Drng
                        Rlrow = ActiveWorkbook.Sheets("Sheet2").Range("B301").End(xlUp).Row + 1
                    ''' 
Populate Declaration ''''
                        
If Fpass False Then
                            ActiveWorkbook
.Sheets("Sheet1").Range("D8").Value ws.Cells(Dcell.Row1).Text
                            ActiveWorkbook
.Sheets("Sheet1").Range("D12").Value ws.Cells(Dcell.Row2).Text
                            Fpass 
True
                        End 
If
                    
''''''' Populate Sheet2                        ActiveWorkbook.Sheets("Sheet2").Cells(Rlrow, 2).Value = ws.Cells(Dcell.Row, 3).Text
                        ActiveWorkbook.Sheets("Sheet2").Cells(Rlrow, 3).Value = ws.Cells(Dcell.Row, 4).Text
                        ActiveWorkbook.Sheets("Sheet2").Cells(Rlrow, 4).Value = ws.Cells(Dcell.Row, 5).Text
                    Next Dcell
                Else
                    For Each Dcell In Drng
                        Rlrow = ActiveWorkbook.Sheets("Sheet2").Range("B301").End(xlUp).Row + 1
                    ''' 
Populate Sheet1 ''''
                        
If Fpass False Then
                            
''''''' first remove existing data in Sheet2 ''''
                            ActiveWorkbook.Sheets("Sheet2").Range("B6:D" & Rlrow).ClearContents
                            '''''''''''''''''''''''''''''''''''''''''''''
                            
ActiveWorkbook.Sheets("Sheet1").Range("D8").Value ws.Cells(Dcell.Row1).Text
                            ActiveWorkbook
.Sheets("Sheet1").Range("D12").Value ws.Cells(Dcell.Row2).Text
                            Fpass 
True
                            Rlrow 
ActiveWorkbook.Sheets("Sheet2").Range("B301").End(xlUp).Row 1
                        End 
If
                            
ActiveWorkbook.Sheets("Sheet2").Cells(Rlrow2).Value ws.Cells(Dcell.Row3).Text
                            ActiveWorkbook
.Sheets("Sheet2").Cells(Rlrow3).Value ws.Cells(Dcell.Row4).Text
                            ActiveWorkbook
.Sheets("Sheet2").Cells(Rlrow4).Value ws.Cells(Dcell.Row5).Text
                    Next Dcell
                End 
If
                Exit 
Sub
                            End 
If
           
ActiveWorkbook.Close savechanges:=True '''' Close and save the current Sheet
        Next Item
End With
Application
.DisplayAlerts True
End Sub 
Reply With Quote
  #62  
Old 04-16-2015, 04:09 PM
charlesdh charlesdh is offline Creating multiple spreadsheets based on text Windows 7 32bit Creating multiple spreadsheets based on text Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

HI,

I'll check it. It should only populate the date selected.
Reply With Quote
  #63  
Old 04-16-2015, 04:44 PM
charlesdh charlesdh is offline Creating multiple spreadsheets based on text Windows 7 32bit Creating multiple spreadsheets based on text Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Check and make are the info is sent to the correct location in the template sheets.

Gotta run..

Good you found the fist problem
Reply With Quote
  #64  
Old 04-17-2015, 12:17 PM
charlesdh charlesdh is offline Creating multiple spreadsheets based on text Windows 7 32bit Creating multiple spreadsheets based on text Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,

I thought you posed that you fixed the "Date" problem.
Let me know.

Also you need to make sure the "Vendors" file format is the same as the "template" format.
Otherwise the data in sheet1 will not populate correctly. Also as mentioned you need to make suer the "Template" sheet names and the same in the "Vendors" file. Make sure you adjust your code for this.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating multiple spreadsheets based on text Creating a table that automatically updates based on entries of a heading in the document cahphoenix Word 3 10-29-2014 01:11 PM
Creating multiple spreadsheets based on text I need to add multiple values based on multiple criteria in a cell not sure what to do AUHAMM Excel 3 10-27-2014 09:11 PM
Creating multiple spreadsheets based on text Need help creating a Word document that is populated based on certain selected values alidaanish Word 1 01-10-2014 10:44 PM
Creating multiple spreadsheets based on text Creating Report based on 'Task Summary' and 'Sub Tasks' alijahed Project 1 02-01-2013 04:20 AM
Creating multiple spreadsheets based on text Creating formula based on if data is correct in cell MattMurdock Excel 1 08-06-2012 03:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft