New to VB and macro

Blastphemist

New Member
Joined
Apr 16, 2013
Messages
5
I'm trying to take a csv file and dump it into a worksheet tab. The magic will create a sheet for each employee that will list the lines in the csv which pertain to that employee.
Code:
EmpName, Emptask
Sally, talk to charlie
Dave, talk to Andrew
Sally, talk to Robert
Charlie, talk to Andrew
Should end up with 3 tabs, named Sally tasks, Dave tasks, Charlie tasks.
Sally tasks should have 2 lines in it, the others 1 each.

I am confused. The other bug in the works is that I am using Office 2010 (Windows) and I would prefer that this work in MacOffice 2008.

Thanks for any and all suggestions.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Use this as a model:

Code:
Sub marine()
Dim I As Long, v As String, sh As Worksheet
Dim N As Long
'
'     make the tabs
'
Workbooks.Open Filename:="C:\TestFolder\x.csv"
Set sh = ActiveSheet
For I = 2 To Cells(Rows.Count, "A").End(xlUp).Row
    sh.Activate
    v = Cells(I, 1).Value
    If SheetExists(v) Then
    Else
        Sheets.Add
        ActiveSheet.Name = v
    End If
Next
'
'     croupier the data
'
sh.Activate
For I = 2 To Cells(Rows.Count, "A").End(xlUp).Row
    v = sh.Cells(I, 1).Value
    N = Sheets(v).Cells(Rows.Count, "A").End(xlUp).Row + 1
    sh.Cells(I, "A").EntireRow.Copy Sheets(v).Cells(N, 1)
Next
End Sub




Function SheetExists(strWSName As String) As Boolean
    Dim ws As Worksheet
    On Error Resume Next
    Set ws = Worksheets(strWSName)
    If Not ws Is Nothing Then SheetExists = True
    'Boolean Function assumed To be False unless Set To True
End Function
 
Upvote 0
I'm definitely in the right place! After changing some things because my real data is different, I have done it. Thank you so much!

Next question, is it a simple thing to (instead of looking at a external file) look at a tab? My dream is to have this be a template (read only) into which a person would paste the contents of the csv, and the macro would auto-spawn the worksheets. My gut says it can happen, but I don't know any of the commands.
 
Upvote 0

Forum statistics

Threads
1,203,082
Messages
6,053,422
Members
444,662
Latest member
AaronPMH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top