Results 1 to 3 of 3

How to check if a name in one sheet exists in other sheet.

Threaded View

  1. #1
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    How to check if a name in one sheet exists in other sheet.

    Hello Forum Members,

    I have to maintain the sales data in a workbook. This workbook has two sheets, one is Input Data and the other is Daily Sales.

    In Input Data sheet I input the sale data of the salesmen who have sold an item that day. The size of data may vary everyday.

    I am new to vba and trying to do this step by step (Please see the code). I don't know if I have written the code correctly but its working for me. There may be some better way to write it but this is beyond my capability.

    Now I am stuck at some point that how can I check whether a salesman no. is present in Input Data sheet and not present in Daily Sales sheet, and if so I need to put that salesman no. and its record in last empty row of Daily Sales Sheet. And if it is found in both sheet, I have to calculate that how much items every salesman has sold today. In Input Data sheet the "sold items" column contains the total sold items so far and I get new data everyday.

    On Daily Sales sheet, after transferring the initial data from the Input Data sheet, I have to enter the today's date in cells E1,F1,G1,H1.....and so on, so that I know how many items every salesman is selling everyday.

    This scenario may be easy for you members, but I am totally lost. So I need the guidance from you experts that how to write a code for the above scenario.

    Sub TransferInitialDataToDailSales()
    Dim sh1 As Worksheet
    Dim sh2 As Worksheet
    
    Set sh1 = ThisWorkbook.Sheets("Input Data")
    Set sh2 = ThisWorkbook.Sheets("Daily Sales")
    
    idlrow = sh1.Cells(Rows.Count, 1).End(xlUp).Row
    'MsgBox idlrow
    
    dslrow = sh2.Cells(Rows.Count, 1).End(xlUp).Row
    'MsgBox dslrow
    
    idlcol = sh1.Cells(1, Columns.Count).End(xlToLeft).Column
    'MsgBox idlcol
    
    dslcol = sh2.Cells(1, Columns.Count).End(xlToLeft).Column
    'MsgBox dslcol
    
    'Code to paste the initial data if no salesman no. is listed in column A of Daily Sales Sheet
    
    For i = 2 To idlrow
        If sh2.Cells(i, 1) = "" Then
        sh2.Cells(i, 1) = sh1.Cells(i, 1)
        sh2.Cells(i, 2) = sh1.Cells(i, 2)
        sh2.Cells(i, 3) = sh1.Cells(i, 3)
        sh2.Cells(i, 4) = sh1.Cells(i, 4)
    
        End If
    Next i
    
    'The following code changes the Col. B & C to date format
    sh2.Range("B:C").NumberFormat = "dd/mm/yyyy"
    
    'Deleting some data purposely to write another code to check
    'if any value from column A in Input Data is absent,
    'put that record in the last row of Daily Sales sheet.
    sh2.Range("A21:D" & dslrow).Delete
    
    ''????? Code here to check if a salesman no. exists in Input Data sheet(after input of new data),
    ''But does not exist in Daily Sales sheet. If so the new salesman data should be entered on
    ''the last empty row of Daily Sales sheet provided only sold item entry must be copied to the
    ''last empty column of sheet Daily Sales which will contain today's date,
    ''Otherwise if the salesman no. is found in Daily Sales sheet, I have to calculate how many items 
    ''he has sold today and place it on the last empty column of that salesman's row.
    
    
    
    End Sub
    Thanks in advance.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Check to see if sheet exists
    By jet2004uk in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-16-2013, 03:43 AM
  2. Replies: 1
    Last Post: 05-29-2013, 01:20 PM
  3. Check to see if a sheet exists
    By michaelbails in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-26-2010, 01:08 AM
  4. [SOLVED] check if the sheet/tag exists
    By Alex in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-14-2006, 05:10 PM
  5. [SOLVED] How to check from VBA if sheet exists?
    By Alen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-02-2006, 08:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1