I want to Split & save the data in different workbook

R

Ron de Bruin

Yes it is possible but if you are not the only user you must add a lot of error checking

If you split the data the sheets will be names after every unique value in the column.
This name must me in the seperate workbook so you can use a Vlookup formula to find the
sheet name and get the mail address.

If you filter on a different column the next time this will not work
So your filter column must be fixed and the unique values in this column must be in the Vlookup table

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


...

read more »- Hide quoted text -

- Show quoted text -

i have maintain a seprate xl sheet with client customer client code
with their mail id's...what i am thinking is to connect that file with
splited data file to send mails....

is that possible
 
R

Ron de Bruin

BTW: please post on top of this thread and not below.
You must scroll down now every time to read your reply
 
A

Amol

Yes it is possible but if you are not the only user you must add a lot oferror checking

If you split the data the sheets will be names after every unique value in the column.
This name must me in the seperate workbook so you can use a Vlookup formula to find the
sheet name and get the mail address.

If you filter on a different column the next time this will not work
So your filter column must be fixed and the unique values in this column must be in the Vlookup table

--

Regards Ron de Bruinhttp://www.rondebruin.nl/tips.htm




...

read more »- Hide quoted text -

- Show quoted text -

Gr8....this can b done.......

Column A is always for customer code and same we can keep for
permanant.....what is the next step....

How can i send mail through outlook....is there any macro need to be
define in outlook. I already prepare a file of mail address of client
according to their client code. and what if the report if not found
for any given date for particular client..what msg does outlook send
for that
 
A

Amol

ok.....sir

but do we need to create two seprate macro for all mentioned function
or it may include in a single macro...

i think two seprate macro will be better....

need ur guidance
 
R

Ron de Bruin

You have the code to split your data so you have seperate sheets now named after the customer code.

Now create a table in a new worksheet in your workbook named "LookupTable" with in column A the
customer code and in column B the mail address.

Try this test macro

If it is working OK you can change .Display in the macro to .Send

Sub Mail_Every_Worksheet()
'Working in 2000-2007
Dim sh As Worksheet
Dim wb As Workbook
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object
Dim MailAdress As String

TempFilePath = Environ$("temp") & "\"

If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007
FileExtStr = ".xlsm": FileFormatNum = 52
End If

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon

For Each sh In ThisWorkbook.Worksheets
MailAdress = ""
On Error Resume Next
MailAdress = Application.WorksheetFunction.VLookup(sh.Name, Sheets("LookupTable").Range("A1:B3"), 2, False)
On Error GoTo 0

If MailAdress Like "?*@?*.?*" Then

sh.Copy
Set wb = ActiveWorkbook

TempFileName = "Sheet " & sh.Name & " of " _
& ThisWorkbook.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")

Set OutMail = OutApp.CreateItem(0)
With wb
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
With OutMail
.To = MailAdress
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add wb.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.display 'or use .Display
End With
On Error GoTo 0
.Close SaveChanges:=False
End With
Set OutMail = Nothing

Kill TempFilePath & TempFileName & FileExtStr
End If
Next sh

Set OutApp = Nothing

With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


Yes it is possible but if you are not the only user you must add a lot of error checking

If you split the data the sheets will be names after every unique value in the column.
This name must me in the seperate workbook so you can use a Vlookup formula to find the
sheet name and get the mail address.

If you filter on a different column the next time this will not work
So your filter column must be fixed and the unique values in this column must be in the Vlookup table

--

Regards Ron de Bruinhttp://www.rondebruin.nl/tips.htm




...

read more »- Hide quoted text -

- Show quoted text -

Gr8....this can b done.......

Column A is always for customer code and same we can keep for
permanant.....what is the next step....

How can i send mail through outlook....is there any macro need to be
define in outlook. I already prepare a file of mail address of client
according to their client code. and what if the report if not found
for any given date for particular client..what msg does outlook send
for that
 
A

Amol

Its showin compile error on this line

MailAdress =
Application.WorksheetFunction.VLookup(sh.Name,Sheets("LookupTable").Range("A1:B3"),
2, False)


Pls tell me if i understood right

1) I have a file which has a different data in each sheet and each
sheet has name of that particular client code

2) now to send this sheet as a file i have to create a table (with the
instruction given by you )in sheet which is a additional sheet in a
same file

Then i have to run macro

Is it right ??

Or u want me to save a new xl file for client code and mail address
 
R

Ron de Bruin

I think the line is red in the VBA editor

It is one code line Amol
I think the newsgroup split it in two




--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm



Its showin compile error on this line

MailAdress =
Application.WorksheetFunction.VLookup(sh.Name,Sheets("LookupTable").Range("A1:B3"),
2, False)


Pls tell me if i understood right

1) I have a file which has a different data in each sheet and each
sheet has name of that particular client code

2) now to send this sheet as a file i have to create a table (with the
instruction given by you )in sheet which is a additional sheet in a
same file

Then i have to run macro

Is it right ??

Or u want me to save a new xl file for client code and mail address
 
A

Amol

nothing is happening

macro just run and thats all....no result nothing......

what msg i suppose to get after i run this macro
 
R

Ron de Bruin

If nothing happens then this is not correct I think in your test workbook
Now create a table in a new worksheet in your workbook named "LookupTable" with in column A the
customer code and in column B the mail address.



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm



nothing is happening

macro just run and thats all....no result nothing......

what msg i suppose to get after i run this macro
 
A

Amol

I have alredy added one sheet in the workbook where i have other
sheets of customer details

like first sheet is "lookup table" with client code in A column and
email address in B
Second sheet is of one of client code same for second and third

I am running macro in look up table sheet and nothing happens

No error No Result
i have also given name for column A as "customer code" and for B "mail
address"

What else i have to do.........

Can u mail me the macro enabled macro on (e-mail address removed)


Thanxs
 
R

Ron de Bruin

Send me the workbook with the data and your sheet with mail addresses private.
Be sure that the code you have try is in that workbook.

I will look at it tomorrow then for you after work

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


I have alredy added one sheet in the workbook where i have other
sheets of customer details

like first sheet is "lookup table" with client code in A column and
email address in B
Second sheet is of one of client code same for second and third

I am running macro in look up table sheet and nothing happens

No error No Result
i have also given name for column A as "customer code" and for B "mail
address"

What else i have to do.........

Can u mail me the macro enabled macro on (e-mail address removed)


Thanxs
 
A

Amol

But what is the problem...why its not working

what i need to do for that? &

Where i can send the file?
i am using dummy data its just a number and my e mail address only
 
R

Ron de Bruin

But what is the problem...why its not working

Maybe the code is in the wrong place or ?


Mail it to the address on my home page
http://www.rondebruin.nl/



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


But what is the problem...why its not working

what i need to do for that? &

Where i can send the file?
i am using dummy data its just a number and my e mail address only
 
A

Amol

i mailed u the data file

Please chk and revert


Maybe the code is in the wrong place or ?

Mail it to the address on my home pagehttp://www.rondebruin.nl/

--

Regards Ron de Bruinhttp://www.rondebruin.nl/tips.htm


But what is the problem...why its not working

what i need to do for that? &

Where i can send the file?
i am using dummy data its just a number and my e mail address only











...

read more »- Hide quoted text -

- Show quoted text -
 
A

Amol

Hi Ron

Its Working Fine......just few points more to make to more
userfriendly and protected

1. Want to add few more lines in Body Like

Please find attached file

Thanxs and regards etc


2. which file i have to take it is as mail macro file.

Because i have a seprate file which splited client code wise and other
file is of mail address

Can i give a open option in mail address file to open splited file or
i have to copy macro every time in a module to run it

3 want to protect this file for permanat that no one can change any
code in it
 
T

T K

you can use the following macro:

Sub CopyData()





Dim LMainWB As String
Dim LNewWB As String
Dim LRow As Integer
Dim LContinue As Boolean

Dim LColAMaster As String
Dim LColATest As String

Dim LWBCount As Integer
Dim LMsg As String

Dim LPath As String
Dim LFilename As String

Dim LColAValue As String

'Path to save all new workbooks to
LPath = "C:\"


'Retrieve name of the workbook that contains the data
LMainWB = ActiveWorkbook.Name

'Initialize variables
LContinue = True
LRow = 2
LWBCount = 0

'Start comparing with cell A2
LColAMaster = "A2"

'Loop through all column A values until a blank cell is found
While LContinue = True

LRow = LRow + 1
LColATest = "A" & CStr(LRow)

'Found a blank cell, do not continue
If Len(Range(LColATest).Value) = 0 Then
LContinue = False
End If

'Value in column A
LColAValue = Range(LColAMaster).Value

'Found occurrence that did not match, copy data to new workbook
If LColAValue <> Range(LColATest).Value Then

'Copy headings
Range("A1:D1").Select
Selection.Copy

'Add new workbook and paste headings into new workbook
Workbooks.Add
LNewWB = ActiveWorkbook.Name
ActiveSheet.Paste
Range("A1").Select

'Copy data from columns A - D
Windows(LMainWB).Activate
Range(LColAMaster & ":D" & CStr(LRow - 1)).Select
Selection.Copy

'Paste results
Windows(LNewWB).Activate
Range("A2").Select
ActiveSheet.Paste
Range("A1").Select

'Save (and overwrite, if necessary) workbook with name from
column A
'and then close workbook
LFilename = LPath & LColAValue & ".xls"
If Dir(LFilename) <> "" Then Kill LFilename
ActiveWorkbook.SaveAs Filename:=LFilename
ActiveWorkbook.Close

'Go back to Main sheet and continue where left off
Windows(LMainWB).Activate
LColAMaster = "A" & CStr(LRow)

'Keep track of the number of workbooks that have been
created
LWBCount = LWBCount + 1

End If

Wend

Range("A1").Select
Application.CutCopyMode = False

LMsg = "Copy has completed. " & LWBCount & " new workbooks have
been created."
LMsg = LMsg & Chr(10) & "You can find them in the following
directory:" & Chr(10) & LPath

MsgBox LMsg

End Sub


*** Sent via Developersdex http://www.developersdex.com ***
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top