Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a spreadsheet that I want to track people and their expiration dates. One of the sheets is everyone in my unit. I want another sheet to pull the names of individuals whose passports are expired or they don't have one yet. I used this expression to pull the names =IF(OR('Whole Squad'!B2="None", 'Whole Squad'!B2="exp"),'Whole Squad'!A2,"") but if I use this one it will put the names in the corresponding cell and I want them to be listed from the top so that I don't have to sort. I have an example of the spreadsheet that I can email if you would like to view it. Thank you very much for any help you can provide!
Posted
Updated 10-May-13 19:46pm
v2
Comments
Sergey Alexandrovich Kryukov 10-May-13 16:20pm    
It makes no sense at all. A formula of what? macro of what?
I consider it as an off-topic questions. A software developer would understand that there are many different products and would not consider this (spreadsheet) activity as programming.
—SA
Maciej Los 11-May-13 2:59am    
I'm not so sure it's an off-topic question. Please, see my answer ;)
Sergey Alexandrovich Kryukov 11-May-13 23:09pm    
I explained why did I say it's off-topic. A qualified inquirer is supposed to be a developer who is supposed to think more reasonably...
—SA
Flash0478 13-May-13 9:34am    
I'm sorry Sergey Alexandrovich Kryukov. I should have mentioned that I have no programming experience. I am just looking for help and would like to learn more than I know now.

1 solution

I do not understand you... If you don't want to use formula, why are you asking about which is better: macro or formula? If you want to enumerate / list employees from the top of the second workbook/worksheet, because you don't want to sort data on formula column, you need to use VBA code (macro).

There is nothing hard to do!

Please, see this article on msdn site: Looping Through a Range of Cells [Excel 2003 VBA Language Reference][^]

Example:
VB
Option Explicit

Sub EnumEmplExpPassDate()
'declare variables
Dim srcWbk As Workbook, dstWbk As Workbook 'src and dest workbooks
Dim srcWsh As Worksheet, dstWsh As Worksheet 'src and dest worksheets
Dim i As Integer, j As Integer 'iter.

On Error GoTo Err_EnumEmplExpPassDate
    
    Set srcWbk = ThisWorkbook 'refer to workbook in which is macro
    Set dstWbk = Workbooks.Add 'add new workbook
    Set srcWsh = srcWbk.Worksheets(1) 'refer to the source sheet with employees names
    'or
    'Set srcWsh = srcwbk.Worksheets("Whole Squad")
    Set dstWsh = dstWbk.Worksheets(1) 'refer to the destination sheet, where you want to list people with expired passpord


    i = 2 'start from row 2 in src sheet
    j = 2 'start from row 2 in dest. sheet
    
    Do While srcWsh.Range("A" & i) <> ""
        'check status
        If srcWsh.Range("B" & i) = "Non" Or srcWsh.Range("B" & i) = "Exp" Then
            srcWsh.Range("A" & i).Copy dstWsh.Range("A" & j) 'copy data
            'if you want to copy the range of cells
            'srcWsh.Range("A" & i & "C" & i).Copy dstWsh.Range("A" & j) 'copy data
            j = j + 1 'increase counter in dst sheet
        End Select
        i = i + 1 'increase counter in src sheet
    Loop

    
'exit code
Exit_EnumEmplExpPassDate:
    On Error Resume Next 'ignore errors
    'clean up ;)
    Set srcWbk = Nothing
    Set dstWbk = Nothing
    Set srcWsh = Nothing
    Set dstWsh = Nothing
    Exit Sub

'error handler
Err_EnumEmplExpPassDate:
    MsgBox Err.Number, vbExclamation, Err.Number
    Resume Exit_EnumEmplExpPassDate
End Sub
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 11-May-13 23:09pm    
...do you see my point?
However, this answer is reasonable. My 5.
—SA
Maciej Los 12-May-13 14:41pm    
Thank you, Sergey ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900