Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-18-2015, 10:40 PM
Niclasfa Niclasfa is offline Excel VBA Macros Windows 8 Excel VBA Macros Office 2013
Novice
Excel VBA Macros
 
Join Date: Apr 2015
Posts: 13
Niclasfa is on a distinguished road
Default Excel VBA Macros

Hey guys. I am having trouble understanding requirements.

I would appreciate any and all productive guidance feedback, thank you in advance.

So basically these are the excel VBA Macro requirements.

1. Macro mcrImport



to import eight state/territory workbooks each into their own separate sheets in template National. Your macro should accomplish the eight imports using looping. The macro will be attached to the button with caption Import on the Summary sheet.


2. Macro mcrCombine

to combine the eight new sheets into one new sheet called Combined. The data should begin from row 2 in sheet Combined to leave room for column headings. After combining the separate eight sheets, the macro should delete the eight separate state/territory sheets. The macro will be attached to the button with caption Combine on the Summary sheet.


3. Macro mcrValidate

to perform validate and summarise tasks according to the details below. The macro will be attached to the button with caption Validate on the Summary sheet
Reply With Quote
  #2  
Old 07-19-2015, 12:17 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline Excel VBA Macros Windows 7 64bit Excel VBA Macros Office 2010 64bit
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,790
Pecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant futurePecoflyer has a brilliant future
Default

Is this some kind of homework?
__________________
Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post
Reply With Quote
  #3  
Old 07-19-2015, 12:35 AM
macropod's Avatar
macropod macropod is offline Excel VBA Macros Windows 7 64bit Excel VBA Macros Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Sure looks like it to me...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 07-19-2015, 04:17 AM
Niclasfa Niclasfa is offline Excel VBA Macros Windows 8 Excel VBA Macros Office 2013
Novice
Excel VBA Macros
 
Join Date: Apr 2015
Posts: 13
Niclasfa is on a distinguished road
Default

No guys it's not any type of home work except the real kind of home work. The kind that earns you money.

I work in Web development for a small removal company. The only problem is. I am the only guy who is required to do all the I.T stuff. I agreed to look into it over the weekend and that is what I am doing.

I have the templates. I discussed with the manager about my options and I told her I would be able to find a solution.
Reply With Quote
  #5  
Old 07-19-2015, 04:45 AM
macropod's Avatar
macropod macropod is offline Excel VBA Macros Windows 7 64bit Excel VBA Macros Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your 'project description' seems to presuppose the existence of a userform, or at least worksheets with ActiveX controls, and a set of workbooks, one of which is called 'National', with a Summary sheet, a Combined sheet, plus eight state/territory workbooks. Without detailed knowledge of the layouts of the userform (including its command buttons, etc.) or ActiveX controls and these various workbooks & worksheets, it would be impossible for anyone to provide any meaningful code.

So, before anyone could make a start on this, you will need to provide at least the empty 'National' workbook, including its userform/ActiveX controls and the Summary & Combined sheets, plus at least one State workbook with some sample data. You can attach workbooks to a post via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.

I also can't see why anyone would specify that particular macro names (mcrImport, mcrCombine, mcrValidate) be used or that mcrImport "should accomplish the eight imports using looping", when nothing you've posted indicates why looping would be needed...

As for wanting a macro "to perform validate and summarise tasks according to the details below", given that you haven't provided any of the said details, that one's going nowhere.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 07-19-2015, 04:22 PM
Niclasfa Niclasfa is offline Excel VBA Macros Windows 8 Excel VBA Macros Office 2013
Novice
Excel VBA Macros
 
Join Date: Apr 2015
Posts: 13
Niclasfa is on a distinguished road
Default

Thank you for your feedback. I have attached screen shots of all relevant documentation. If required I can upload the documents.

List of documents I was given
http://postimg.org/image/7t7ooq0lx/

Excel Table for VBA coding
http://postimg.org/image/950qnedq5/

Word Doc with bookmarks to import data from
http://postimg.org/image/3pft6pd6t/

Word Doc VBA side
http://postimg.org/image/p9srvckn1/

I hope this helps you get a better understanding. If you require the documents I can upload them.
Reply With Quote
  #7  
Old 07-19-2015, 05:39 PM
Niclasfa Niclasfa is offline Excel VBA Macros Windows 8 Excel VBA Macros Office 2013
Novice
Excel VBA Macros
 
Join Date: Apr 2015
Posts: 13
Niclasfa is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Your 'project description' seems to presuppose the existence of a userform, or at least worksheets with ActiveX controls, and a set of workbooks, one of which is called 'National', with a Summary sheet, a Combined sheet, plus eight state/territory workbooks. Without detailed knowledge of the layouts of the userform (including its command buttons, etc.) or ActiveX controls and these various workbooks & worksheets, it would be impossible for anyone to provide any meaningful code.

So, before anyone could make a start on this, you will need to provide at least the empty 'National' workbook, including its userform/ActiveX controls and the Summary & Combined sheets, plus at least one State workbook with some sample data. You can attach workbooks to a post via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.

I also can't see why anyone would specify that particular macro names (mcrImport, mcrCombine, mcrValidate) be used or that mcrImport "should accomplish the eight imports using looping", when nothing you've posted indicates why looping would be needed...

As for wanting a macro "to perform validate and summarise tasks according to the details below", given that you haven't provided any of the said details, that one's going nowhere.
Thank you for your feedback. I attached three documents that should be able to help.
I hope they uploaded properly.
Attached Files
File Type: xltm National.xltm (13.3 KB, 13 views)
File Type: dotm WelcomeAboard.dotm (299.8 KB, 12 views)

Last edited by macropod; 07-21-2015 at 05:52 AM. Reason: Data workbook containing DOB info, etc. deleted for privacy reasons
Reply With Quote
  #8  
Old 07-20-2015, 02:32 AM
macropod's Avatar
macropod macropod is offline Excel VBA Macros Windows 7 64bit Excel VBA Macros Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try the code below. I've implemented the mcrImport & mcrCombine macros. The macro assumes the National & State files are all kept in the same folder.

You still haven't provided anything relevant to the mcrValidate macro and your WelcomeAboard template, though, would be better implemented as a mailmerge main document, for which no macros would be required.

Code:
Option Explicit
Dim StrSrc As String, StrState As String, xlWkBk As Workbook, xlWkSht As Worksheet
Dim i As Long, lRowSrc As Long, lColSrc As Long, lRowTgt As Long
Sub mcrImport()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim ArrState As Variant
ArrState = Array("NSW", "Vic", "Qld", "WA", "SA", "Tas", "ACT", "NT")
For i = 0 To UBound(ArrState)
  StrState = ArrState(i)
  StrSrc = ActiveWorkbook.Path & "\" & StrState & ".xls"
  If Dir(StrSrc) <> "" Then Call AddSheet(StrState, StrSrc)
Next
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Sub AddSheet(StrState As String, StrSrc As String)
With ActiveWorkbook
  Set xlWkSht = .Worksheets.Add(After:=.Worksheets(.Worksheets.Count))
  With xlWkSht
    .Name = StrState
    'Populate the header row
    .Range("A1").Value = "Family Name"
    .Range("B1").Value = "Given Name"
    .Range("C1").Value = "Gender"
    .Range("D1").Value = "D.O.B."
    .Range("E1").Value = "Address"
    .Range("F1").Value = "Suburb"
    .Range("G1").Value = "State"
    .Range("H1").Value = "Post Code"
    .Range("I1").Value = "Role"
    Call GetData(StrSrc)
    .Paste Destination:=.Cells(2, 1)
  End With
End With
Set xlWkSht = Nothing
End Sub
Sub GetData(StrSrc As String)
Set xlWkBk = Workbooks.Open(Filename:=StrSrc, ReadOnly:=True, AddToMRU:=False)
With xlWkBk
  With .Worksheets(1).UsedRange
    lRowSrc = .Cells.SpecialCells(xlCellTypeLastCell).Row
    lColSrc = .Cells.SpecialCells(xlCellTypeLastCell).Column
    .Range("A1", .Cells(lRowSrc, lColSrc)).Copy
  End With
  .Close 0
End With
Set xlWkBk = Nothing
End Sub
Sub mcrCombine()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim ArrState As Variant
ArrState = Array("NSW", "Vic", "Qld", "WA", "SA", "Tas", "ACT", "NT")
With ActiveWorkbook
  Set xlWkSht = .Worksheets.Add(After:=.Worksheets(1))
  xlWkSht.Name = "Combined"
  With xlWkSht
    'Populate the header row
    .Range("A1").Value = "Family Name"
    .Range("B1").Value = "Given Name"
    .Range("C1").Value = "Gender"
    .Range("D1").Value = "D.O.B."
    .Range("E1").Value = "Address"
    .Range("F1").Value = "Suburb"
    .Range("G1").Value = "State"
    .Range("H1").Value = "Post Code"
    .Range("I1").Value = "Role"
  End With
  For i = 0 To UBound(ArrState)
    lRowTgt = lRowTgt + 1
    StrState = ArrState(i)
    If SheetExists(StrState) = True Then
      Call ImportSheet(StrState)
      .Worksheets(StrState).Delete
    End If
  Next
End With
Set xlWkSht = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Sub ImportSheet(StrSrc As String)
With ActiveWorkbook
  With .Worksheets(StrSrc).UsedRange
    lRowSrc = .Cells.SpecialCells(xlCellTypeLastCell).Row
    lColSrc = .Cells.SpecialCells(xlCellTypeLastCell).Column
    .Range("A2", .Cells(lRowSrc, lColSrc)).Copy
  End With
  With .Worksheets("Combined")
    lRowTgt = .UsedRange.Cells.SpecialCells(xlCellTypeLastCell).Row + 1
    .Paste Destination:=.Cells(lRowTgt, 1)
  End With
End With
End Sub
Function SheetExists(SheetName As String) As Boolean
' returns TRUE if the sheet exists in the active workbook
SheetExists = False
On Error GoTo NoSuchSheet
If Len(Sheets(SheetName).Name) > 0 Then
  SheetExists = True
  Exit Function
End If
NoSuchSheet:
End Function
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 07-20-2015, 04:24 AM
Niclasfa Niclasfa is offline Excel VBA Macros Windows 8 Excel VBA Macros Office 2013
Novice
Excel VBA Macros
 
Join Date: Apr 2015
Posts: 13
Niclasfa is on a distinguished road
Default

Thank you.

I will attach Doc Template now with Macro Requirements. If you require any of the other documents, just let me know.

Word macros

mcrOK: to populate the bookmarks within the letter text in the body of the template. The macro will be attached to the UserForm button with caption OK.

mcrLog: to append person data to the text file Latelog.txt and hide the UserForm. The macro will be attached to the UserForm button with caption Log.

mcrClear: to clear the UserForm fields. The macro will be attached to the UserForm button with caption Clear.

mcrClose: to close the UserForm. The macro will be attached to the UserForm button with caption Close.
Attached Files
File Type: dotm WelcomeAboard.dotm (299.8 KB, 17 views)
Reply With Quote
  #10  
Old 07-20-2015, 05:06 AM
macropod's Avatar
macropod macropod is offline Excel VBA Macros Windows 7 64bit Excel VBA Macros Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I do have to wonder whether you paid any attention to what I said about your WelcomeAboard template and which you quoted in your own reply:
Quote:
your WelcomeAboard template, though, would be better implemented as a mailmerge main document, for which no macros would be required
Simply re-attaching the same template isn't going to cause me to change that advice, let alone do any programming!
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 07-20-2015, 06:05 AM
Niclasfa Niclasfa is offline Excel VBA Macros Windows 8 Excel VBA Macros Office 2013
Novice
Excel VBA Macros
 
Join Date: Apr 2015
Posts: 13
Niclasfa is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
I do have to wonder whether you paid any attention to what I said about your WelcomeAboard template and which you quoted in your own reply:

Simply re-attaching the same template isn't going to cause me to change that advice, let alone do any programming!
Sorry. Between embedding new java onto over 100 pages and dealing with Microsoft azure I didn't take the time to read your comments properly. I apologize.

Its midnight at the moment for me so I'll have to review it in the morning.
Reply With Quote
  #12  
Old 07-20-2015, 04:24 PM
Niclasfa Niclasfa is offline Excel VBA Macros Windows 8 Excel VBA Macros Office 2013
Novice
Excel VBA Macros
 
Join Date: Apr 2015
Posts: 13
Niclasfa is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Try the attached workbook. I've implemented the mcrImport & mcrCombine macros. The macro assumes the National & State files are all kept in the same folder.

You still haven't provided anything relevant to the mcrValidate macro and your WelcomeAboard template, though, would be better implemented as a mailmerge main document, for which no macros would be required.
Morning. While mail merge would probably be the best solution and I trust your knowledge. I have been told by the admin manager that a macro is required. I can't unfortunately make any changes to the outlined request as they come from a subsidiary company.

So in regards to the mcrValidate. I was given the following information.

In row 1 of sheet Combined the following column headings: Last name, First name, Gender, DOB, Address, Suburb, State, Postcode, Role, Category.
Standardise all fonts to plain Arial 12 pt.

The column Category in sheet Combined was not in the original states data. Its purpose is to record the age category for each member.

The various categories from Junior to Great Grand Master
Junior - Under 18
Senior - 18+
Master - 40+
Grand Master - 50+
Great Grand Master - 60+

For each member data, generate the age category for column Category. for each row subtract DOB from your Nationals date to find the member's expected age on the day of competition, then compare with the category table below. Write out the category data for the member in full.

I hope this helps. You have already helped immensely and I do appreciate it.
Reply With Quote
  #13  
Old 07-20-2015, 08:53 PM
macropod's Avatar
macropod macropod is offline Excel VBA Macros Windows 7 64bit Excel VBA Macros Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Niclasfa View Post
While mail merge would probably be the best solution and I trust your knowledge. I have been told by the admin manager that a macro is required. I can't unfortunately make any changes to the outlined request as they come from a subsidiary company.
Perhaps, then, your company would prefer to pay someone to do this, rather than wasting the time of community volunteers. I'm disinclined to write code just to amuse people who aren't interested in an efficient workflow. It seems whoever specified this project is wedded to a process more than to an outcome.

That said, your WelcomeAboard template has a quite unnecessary userform and nothing to indicate whether or how the fields in it should be filled. I say unnecessary because, even with a macro, everything could be done in the body of the document, using content controls.

Presumably the data are meant to come from the workbook, but there's nothing to indicate how any given record from the hundreds (or more) in the workbook might be used to populate the userform. Do the people behind this imagine the userform is going to fill itself out programmatically, without human intervention?
Quote:
Originally Posted by Niclasfa View Post
So in regards to the mcrValidate. I was given the following information.

In row 1 of sheet Combined the following column headings: Last name, First name, Gender, DOB, Address, Suburb, State, Postcode, Role, Category.
Standardise all fonts to plain Arial 12 pt.

The column Category in sheet Combined was not in the original states data. Its purpose is to record the age category for each member.

The various categories from Junior to Great Grand Master
Junior - Under 18
Senior - 18+
Master - 40+
Grand Master - 50+
Great Grand Master - 60+

For each member data, generate the age category for column Category. for each row subtract DOB from your Nationals date to find the member's expected age on the day of competition, then compare with the category table below. Write out the category data for the member in full.
That's all very well but, unless you know what the date of the competition will be when the macro is run (and you've provided nothing to indicate where that date might come from), that is impossible. Although cell B5 on the Summary sheet has a date for the next national competition, that cell has a formula (=TODAY()), which will simply update itself every day. to cope with that the macro has to inserts a formula into every cell in the Category column. Otherwise, the output could be wrong the following day... In any event, even if you use fixed date in cell B5 on the Summary sheet, a formula allows those calculations to be updated later if the date needs changing (e.g. if a new competition date is decided upon), whereas a result generated by a macro at run-time would be static.

Finally, the Category info isn't provided for in the WelcomeAboard template, so I'm not sure what the point of those calculations is.

Updated workbook attached.
Attached Files
File Type: xlsm National.xlsm (27.4 KB, 17 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #14  
Old 07-20-2015, 10:04 PM
Niclasfa Niclasfa is offline Excel VBA Macros Windows 8 Excel VBA Macros Office 2013
Novice
Excel VBA Macros
 
Join Date: Apr 2015
Posts: 13
Niclasfa is on a distinguished road
Default

I understand what you are saying. I would be happy to pay for your services. If you would like to send me a quote to my email address.

Last edited by macropod; 07-20-2015 at 10:11 PM. Reason: email address removed for privacy
Reply With Quote
  #15  
Old 07-20-2015, 10:14 PM
macropod's Avatar
macropod macropod is offline Excel VBA Macros Windows 7 64bit Excel VBA Macros Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Sorry, but I don't do paid work. In any event, it's a trivial project. Someone closer to home for you, who may be interested, is another MS MVP, Doug Robbins - http://au.linkedin.com/pub/doug-robbins/11/139/318
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel VBA Macros Excel 2000 macros in excel 13 terryg Excel 1 03-30-2015 05:18 AM
Excel VBA Macros Excel 97 macros no longer run PeteNC Excel 3 12-07-2014 06:22 PM
Excel VBA Macros Run macros between excel and access Jhouk5244 Office 1 08-18-2011 11:06 AM
macros to excel evh Excel Programming 0 07-20-2011 10:12 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:23 PM.


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