Question

Documenting VBA Code

Asked by: cjinsocal581

Thanks to GirardAndrew for the following code. What I need to know is how it references to each item in the spreadsheet. I am learning VBA code and am trying to get a handle on how it is different from VBScript. How references to rows, columns, cells, etc.

So if someone could help by commenting lines on each line of code to explain how they interact with the spreadsheet, I would be most appreciative.

Public Category As String
Public CustRef As String
Public FirstName As String
Public LastName As String
Public Exec As String
Public UniqueID As String
Public xCategory As String
Public xCustRef As String
Public xFirstName As String
Public xLastName As String
Public xExec As String
Public xUniqueID As String
 
Public Function ConvertColumn(ColumnNumber As Integer)
    ConvertColumn = WorksheetFunction.Substitute(Cells(1, ColumnNumber).AddressLocal(RowAbsolute = True, ColumnAbslute = True), 1, "")
End Function
 
Private Sub InsertEntry(Category As String, CustRef As String, FirstName As String, LastName As String, Exec As String, RowN As Integer, UniqueID As String)
    If WorksheetFunction.CountIf(Sheets(Category).Range("X:X"), UniqueID) > 0 Then Exit Sub
    Sheets(Category).Range("A" & RowN).EntireRow.Insert
    Sheets(Category).Range("A" & RowN) = CustRef
    Sheets(Category).Range("E" & RowN) = FirstName
    Sheets(Category).Range("F" & RowN) = LastName
    Sheets(Category).Range("X" & RowN) = UniqueID
End Sub
 
Private Sub SendData()
    xCategory = ConvertColumn(WorksheetFunction.Match("Category", Range("1:1"), 0))
    xCustRef = ConvertColumn(WorksheetFunction.Match("Customer Reference Value", Range("1:1"), 0))
    xFirstName = ConvertColumn(WorksheetFunction.Match("First Name", Range("1:1"), 0))
    xLastName = ConvertColumn(WorksheetFunction.Match("Last Name", Range("1:1"), 0))
    xExec = ConvertColumn(WorksheetFunction.Match("Sr. Exec.", Range("1:1"), 0))
    xUniqueID = ConvertColumn(WorksheetFunction.Match("Unique ID", Range("1:1"), 0))
    For i = 2 To WorksheetFunction.CountA(Range("B:B"))
        Category = Range(xCategory & i)
        CustRef = Range(xCustRef & i)
        FirstName = Range(xFirstName & i)
        LastName = Range(xLastName & i)
        Exec = Range(xExec & i)
        UniqueID = Range(xUniqueID & i)
        On Error Resume Next
        Select Case Category
            Case "WC"
            Case "Corp"
                InsertEntry Category, CustRef, FirstName, LastName, Exec, WorksheetFunction.Match(Exec, Sheets(Category).Range("I:I"), 0), UniqueID
            Case Else
                InsertEntry Category, CustRef, FirstName, LastName, Exec, 7, UniqueID
        End Select
    Next i
End Sub
 
 
Private Sub CommandButton1_Click()
SendData
End Sub

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-21 at 07:38:07ID24671526
Topic

Microsoft Excel Spreadsheet Software

Participating Experts
3
Points
500
Comments
5

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. VBScript and VBA (Excel) problems
    I am driving an Excel Spreadsheet from VBScript, so I start off with a statement such as: Set Spreadsheet = getobject("Q:\TIMS3\Setup\TIMS3 Build Control.xls") I am then able to access plenty of the VBA methods and properties with no problems, but I have hit two s...
  2. VBScript and VBA (Excel) problems
    I am driving an Excel Spreadsheet from VBScript, so I start off with a statement such as: Set Spreadsheet = getobject("Q:\TIMS3\Setup\TIMS3 Build Control.xls") I am then able to access plenty of the VBA methods and properties with no problems, but I have hit a sna...
  3. Excel VBA - formatting Cell color
    I am using a Spreadsheet object in conjunction with my ASP code. I found various properties for changing an Excel spreadsheet but can't figure out how to change the cell's background. Set objSpreadsheet = Server.CreateObject("OWC.Spreadsheet") objSpreadsheet.C...
  4. VBA
    I am in the middle of a long winded process of automating a daily letter print job. I do not have access to VB so I am trying to do everything in VBA; The process in brief; x amount of files are produced and placed in a particular folder, each file that is letter releted ne...
  5. Adding VBA and Macros to an Interactive Excel Sheet
    I can publish an excel sheet as an interactive sheet from the save as options but can you get macro or VBA code functionality on the web enabled worksheet? If so how?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: CbrinePosted on 2009-08-21 at 10:28:05ID: 25153920

OK,  looks like no one else is gonna take a shot at it, so here goes...

'Setup initial Global Variables
Public Category As String
Public CustRef As String
Public FirstName As String
Public LastName As String
Public Exec As String
Public UniqueID As String
Public xCategory As String
Public xCustRef As String
Public xFirstName As String
Public xLastName As String
Public xExec As String
Public xUniqueID As String
 
Public Function ConvertColumn(ColumnNumber As Integer)
    'Return the results of substitute worksheet function...Seems to return only the the column letter of the column
    'Number passed to it.  Does this by Sustituting 1 with "", since row is always one, you are left with only
    'Column Letter and absolute symbols.(ie.  "$A$")
    ConvertColumn = WorksheetFunction.Substitute(Cells(1, ColumnNumber).AddressLocal(True, True), 1, "")
End Function
Private Sub InsertEntry(Category As String, CustRef As String, FirstName As String, LastName As String, Exec As String, RowN As Integer, UniqueID As String)
 
    'If the passed uniqueID already exists in Column X of passed worksheet(Category) then exit sub
    If WorksheetFunction.CountIf(Sheets(Category).Range("X:X"), UniqueID) > 0 Then Exit Sub
    
    'Insert a row on Sheet(Category) at row(RowN)
    Sheets(Category).Range("A" & RowN).EntireRow.Insert
    'Add data for new record into row(RowN)
    Sheets(Category).Range("A" & RowN) = CustRef
    Sheets(Category).Range("E" & RowN) = FirstName
    Sheets(Category).Range("F" & RowN) = LastName
    Sheets(Category).Range("X" & RowN) = UniqueID
End Sub
 
Private Sub SendData()
 
    'Return Column Letter for String "Category" in row one.  I'm assuming this is for some
    'type of dynamic identification of column headings.  After this is executed, xCategory will
    'hold the column Letter for the Column with heading of Category.
    xCategory = ConvertColumn(WorksheetFunction.Match("Category", Range("1:1"), 0))
    'Same for Column Heading "Customer Reference Value"
    xCustRef = ConvertColumn(WorksheetFunction.Match("Customer Reference Value", Range("1:1"), 0))
    'Same for Column Heading "First Name"
    xFirstName = ConvertColumn(WorksheetFunction.Match("First Name", Range("1:1"), 0))
    'Same for Column heading "Last Name"
    xLastName = ConvertColumn(WorksheetFunction.Match("Last Name", Range("1:1"), 0))
    'Same for Column Heading "Sr. Exec"
    xExec = ConvertColumn(WorksheetFunction.Match("Sr. Exec.", Range("1:1"), 0))
    'Same for column Heading "Unique ID"
    xUniqueID = ConvertColumn(WorksheetFunction.Match("Unique ID", Range("1:1"), 0))
    
    'Cycle through all information in rows to 2 to counta of column B.  This will allow you to loop through all populated
    'rows in combination with column Headings above.
    For i = 2 To WorksheetFunction.CountA(Range("B:B"))
        
        'Set public variables equal to row I and Column Heading based on code above.
        Category = Range(xCategory & i)
        CustRef = Range(xCustRef & i)
        FirstName = Range(xFirstName & i)
        LastName = Range(xLastName & i)
        Exec = Range(xExec & i)
        UniqueID = Range(xUniqueID & i)
        
        'Disable error checking...
        On Error Resume Next
        
        
        'Select actions based on returned value of Category
        Select Case Category
            'If Category is equal to WC, then do nothing
            Case "WC"
            'If Category is equal to "Corp" then run insertEntry sub with passed values
            Case "Corp"
                InsertEntry Category, CustRef, FirstName, LastName, Exec, WorksheetFunction.Match(Exec, Sheets(Category).Range("I:I"), 0), UniqueID
            'If case does not match any of the above values, then Call InsertEntry
            Case Else
                InsertEntry Category, CustRef, FirstName, LastName, Exec, 7, UniqueID
        End Select
    
    'Cycle to next value of i.
    Next i
End Sub

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:

Select allOpen in new window

 

by: GirardAndrewPosted on 2009-08-21 at 10:32:03ID: 25153954

Public Category As String
Public CustRef As String
Public FirstName As String
Public LastName As String
Public Exec As String
Public UniqueID As String
Public xCategory As String
Public xCustRef As String
Public xFirstName As String
Public xLastName As String
Public xExec As String
Public xUniqueID As String
 
Public Function ConvertColumn(ColumnNumber As Integer)
    Rem Converts a column number to its column letter reference
    ConvertColumn = WorksheetFunction.Substitute(Cells(1, ColumnNumber).AddressLocal(RowAbsolute = True, ColumnAbslute = True), 1, "")
End Function
 
Private Sub InsertEntry(Category As String, CustRef As String, FirstName As String, LastName As String, Exec As String, RowN As Integer, UniqueID As String)
    Rem Checks for exitence of entry to acoid duplicates
    If WorksheetFunction.CountIf(Sheets(Category).Range("X:X"), UniqueID) > 0 Then Exit Sub
    Rem Inputs data from source
    Sheets(Category).Range("A" & RowN).EntireRow.Insert
    Sheets(Category).Range("A" & RowN) = CustRef
    Sheets(Category).Range("E" & RowN) = FirstName
    Sheets(Category).Range("F" & RowN) = LastName
    Sheets(Category).Range("X" & RowN) = UniqueID
End Sub
 
Private Sub SendData()
    Rem Assigns variable to column letter reference for every Label/Header
    xCategory = ConvertColumn(WorksheetFunction.Match("Category", Range("1:1"), 0))
    xCustRef = ConvertColumn(WorksheetFunction.Match("Customer Reference Value", Range("1:1"), 0))
    xFirstName = ConvertColumn(WorksheetFunction.Match("First Name", Range("1:1"), 0))
    xLastName = ConvertColumn(WorksheetFunction.Match("Last Name", Range("1:1"), 0))
    xExec = ConvertColumn(WorksheetFunction.Match("Sr. Exec.", Range("1:1"), 0))
    xUniqueID = ConvertColumn(WorksheetFunction.Match("Unique ID", Range("1:1"), 0))
    Rem Start processing source data starting with row 2
    For i = 2 To WorksheetFunction.CountA(Range("B:B"))
        Rem Create variables to values from Source table
        Category = Range(xCategory & i)
        CustRef = Range(xCustRef & i)
        FirstName = Range(xFirstName & i)
        LastName = Range(xLastName & i)
        Exec = Range(xExec & i)
        UniqueID = Range(xUniqueID & i)
        On Error Resume Next
        Rem Verify which sheet to apply entry
        Select Case Category
            Case "WC"
            Case "Corp"
                InsertEntry Category, CustRef, FirstName, LastName, Exec, WorksheetFunction.Match(Exec, Sheets(Category).Range("I:I"), 0), UniqueID
            Case Else
                InsertEntry Category, CustRef, FirstName, LastName, Exec, 7, UniqueID
        End Select
    Next i
End Sub
 
 
Private Sub CommandButton1_Click()
SendData
End Sub
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:

Select allOpen in new window

 

by: BarryTicePosted on 2009-08-21 at 10:51:35ID: 25154142

It figured that by the time I got this done, there would be others. :-)

Take a look at everyone's comments and see who is most helpful.

' Begin by declaring your variables. In this case, they are all strings, used to hold alphanumeric/text values.
Public Category As String
Public CustRef As String
Public FirstName As String
Public LastName As String
Public Exec As String
Public UniqueID As String
Public xCategory As String
Public xCustRef As String
Public xFirstName As String
Public xLastName As String
Public xExec As String
Public xUniqueID As String
 
' Public means make this a function that can be seen by all other subroutines and functions.
' Function declares that it is a function, like a subroutine that can be called, but that returns a value.
' ConvertColumn is the name of the function that is called.
' ColumnNumber is a parameter value passed in to the function that it uses to perform its, uh, function 
Public Function ConvertColumn(ColumnNumber As Integer)
    ' ConvertColumn here is the name of the function. Assigning a value to that variable/function name means that value is what the function returns.
    ' WorksheetFunction is an object that allows you to use VB to apply functions to data as though that function had been invoked directly in the worksheet rather than using the VB code.
    ' .Substitute is the function that it's applying. (See the Excel help for that, if you like.) Essentially, it's replacing one value with a different value. It's often used to replace a substring of text.
    ' In this case, it's targeting the cell returned by Cells(1, ColumnNumber).AddressLocal(RowAbsolute = True, ColumnAbsolute = True).
    ' Cells(1, ColumnNumber) returns a cell object, in this case, row A, in the column passed in by the ColumnNumber parameter passed in to the function. Once you have that cell object, .AddressLocal gets the actual address.
    ' So, "Cells(1, 1).AddressLocal(RowAbsolute = True, ColumnAbsolute = True)" returns "A1"
    ' And, "Cells(1, 7).AddressLocal(RowAbsolute = True, ColumnAbsolute = True)" returns "G1"
    ' Once it has that cell, it's replacing 1 in that cell with "" (nothing), thanks to the Substitute function.
    ' Since it started as, for example, "$A$1" what this gives back is "$A$"
    ' Note that I have corrected a typo in this line, as "ColumnAbsolute" was shown as "ColumnAbslute"
    ConvertColumn = WorksheetFunction.Substitute(Cells(1, ColumnNumber).AddressLocal(RowAbsolute = True, ColumnAbsolute = True), 1, "")
    ' Because all of that was assigned to the "ConvertColumn" variable, that value is returned to the calling subroutine when the function ends.
End Function
 
' Private means this subroutine can only be seen by other subroutines in this module.
' Sub means we're defining a subroutine
' InsertEntry is the name of the subroutine.
' Category, CustRef, FirstName, LastName, Exec, and UniqueID are all string parameters passed in to the subroutine.
' RowN is an integer parameter passed in.
Private Sub InsertEntry(Category As String, CustRef As String, FirstName As String, LastName As String, Exec As String, RowN As Integer, UniqueID As String)
    ' WorksheetFunction (again) allows you to use a worksheet function here in the VB code
    ' The CountIf function tells how many cells in a specified range meet the given criteria.
    ' In this case, it looks at the worksheet whose name is in the Category value passed in.
    ' Within that worksheet, it's looking in the entire X column, as the whole column is the specified range.
    ' Essentially, it checks to see if any of the cells in the X column contain the "UniqueID" value passed in as a parameter.
    ' If any of them do, then don't bother processing, and leave the subroutine ("Exit Sub").
    ' If any of the cells in the range DO contain UniqueID, it falls through to the code below.
    If WorksheetFunction.CountIf(Sheets(Category).Range("X:X"), UniqueID) > 0 Then Exit Sub
    ' Go to the first column of the specified row and insert an entire new row
    Sheets(Category).Range("A" & RowN).EntireRow.Insert
    ' In this new row, put in CustRef, FirstName, LastName and UniqueID values (passed in as parameters) into the A, E, F and X columns
    Sheets(Category).Range("A" & RowN) = CustRef
    Sheets(Category).Range("E" & RowN) = FirstName
    Sheets(Category).Range("F" & RowN) = LastName
    Sheets(Category).Range("X" & RowN) = UniqueID
    ' Having done that, we exit the subroutine
End Sub
 
' Private, again, means only let this be visible to other code in this module.
' Sub means define a subroutine
' SendData is the name of the subroutine
Private Sub SendData()
    ' Into the xCategory variable, insert the value returned by the ConvertColumn function when we send it a column number.
    ' WorksheetFunction we've talked about already. In this case, it's the Match function.
    ' Match looks up a value in a list of values, and returns the closest value to it from the list. (Or, no value, or exact values, depending on how you use it.)
    ' Match returns the location in that list for where the value was found, if it was.
    ' Here, it searches for the word "Category" in the entire first row. If it finds it, it returns the column number.
    ' Once the Match function returns the column number, that column number gets passed as a parameter to the ConvertColumn function.
    ' The ConvertColumn function then replaces any 1 in the first row of the column with nothing.
    ' That text, with the 1 removed, is assigned to the variable at the beginning of the line.
    ' So, for example, if "Category" is in cell D1, "Match("Category", Range("1:1"), 0)" would return a 4, for the fourth column.
    ' The ConvertColumn function then runs with 4 as the parameter being passed in. That would give you "$D$" as the value.
    ' This is done six times: Once for each variable listed here:
    xCategory = ConvertColumn(WorksheetFunction.Match("Category", Range("1:1"), 0))
    xCustRef = ConvertColumn(WorksheetFunction.Match("Customer Reference Value", Range("1:1"), 0))
    xFirstName = ConvertColumn(WorksheetFunction.Match("First Name", Range("1:1"), 0))
    xLastName = ConvertColumn(WorksheetFunction.Match("Last Name", Range("1:1"), 0))
    xExec = ConvertColumn(WorksheetFunction.Match("Sr. Exec.", Range("1:1"), 0))
    xUniqueID = ConvertColumn(WorksheetFunction.Match("Unique ID", Range("1:1"), 0))
    ' WorksheetFunction again. CountA finds how many cells in the specified range are not empty.
    ' So, we're looking for how many cells in column B have something in them. And we're then looping through them, starting with row 2.
    For i = 2 To WorksheetFunction.CountA(Range("B:B"))
        ' For each of the following, assign a range of cells to the variables.
        ' Remember that "xCategory" for example, will contain an absolute pointer to the column, as set by the ConvertColumn function.
        ' The & operator concatenates strings.
        ' So, xCategory could have "$D$" in it, which would make Category be the range "$D$1", if i is 1, or "$D$2" if i is 2.
        ' Essentially, the For loop means, "Do all this for rows 1 and 2" in this case.
        Category = Range(xCategory & i)
        CustRef = Range(xCustRef & i)
        FirstName = Range(xFirstName & i)
        LastName = Range(xLastName & i)
        Exec = Range(xExec & i)
        UniqueID = Range(xUniqueID & i)
        ' The On Error line means if there's an invalid response, keep going.
        On Error Resume Next
        ' Determine your next action based on the value of Category. This is like an If-Then-Else construction.
        Select Case Category
            Case "WC"
            ' If Category is "WC" don't do anything
            Case "Corp"
            ' If Category is "Corp" then run that InsertEntry subroutine we did a while ago.
            ' That adds a row to the specified worksheet with the specified information, if that worksheet doesn't already have that UniqueID value in it.
            ' The value is added at the line determined here by the Match function -- if the value in the Exec variable is found in the I column on the Corp sheet
                InsertEntry Category, CustRef, FirstName, LastName, Exec, WorksheetFunction.Match(Exec, Sheets(Category).Range("I:I"), 0), UniqueID
            Case Else
            ' This isn't the WC category or the Corp category.
            ' Use that same InsertEntry subroutine to add a line to the specified worksheet with the specified data, at row 7.
                InsertEntry Category, CustRef, FirstName, LastName, Exec, 7, UniqueID
        End Select
    ' Next i means, "Well, you've done all this for the situation where i=1, so now set i=2 and try it again"
    ' This continues up to the ending value declared up there in the "For i =" loop.
    Next i
' And we're done with this subroutine.
End Sub
 
 
Private Sub CommandButton1_Click()
' This subroutine is what is invoked by the button click. All it does is call the SendData subroutine.
SendData
End Sub

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:

Select allOpen in new window

 

by: cjinsocal581Posted on 2009-08-28 at 12:54:34ID: 31618873

I appreciate everyone's comments. This one is exactly what I need to get going in the right direction plus get my backup up to speed.

thanks again.

 

by: BarryTicePosted on 2009-08-28 at 13:41:49ID: 25211397

Thank you, cjinsocal581.

Not to complain, by any means, but it in cases where several people have contributed to an overall answer, it is usually a good thing to split the points amongst the best answers for those who have made good contributions.

Glad to have helped!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...