Writing a macro

Solved/Closed
Anna - May 14, 2010 at 07:51 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - May 26, 2010 at 12:24 PM
Hello,

I am trying to get data whcih has been inoutted into one workksheet to copy into another worksheets when it meets a command in one of the columns. I beleieve i need to write a macro for this although i have no macro experience whatsoever.
Can you please help? :)

4 responses

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
May 14, 2010 at 08:14 AM
You question does not have too much detail to give you a good answer. How ever, you can get a good idea of macro if you use the macro recorder of excel. Start the macro, then do what you want to do and stop the macro.This would give you a starting template.
0
Apologies for the lack of information. Basically sheet 1 contains a full list of data, the command will be a Y in one of the columns so when this is inserted i want the whole row to be copied and transferred into another worksheet, worksheet 2. The purpose of this is so the gneral details can be copied across andthen i will expand on this in the different sheet for those that apply. I have no idea how to write a macro therefore its difficult to make a start.
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
May 14, 2010 at 05:33 PM
Are you saying that if a row contains a Y in any column of that row, you want this whole row to be copied to a sheet ?

IF that is the case, what about this other sheet. Will it always exist, should the existing data on the sheet be wiped out or this new data be appended

Could you please upload a sample file with sample data etc on some shared site like https://authentification.site , http://wikisend.com/ , http://www.editgrid.com etc and post back here the link to allow better understanding of how it is now and how you foresee.
0
Here is the link to direct you to my sample workbook.



https://authentification.site/files/22476709/SAMPLE.xls



Many thank



Anna.
0
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
May 25, 2010 at 04:29 PM
You would need to explain more based on sample file. Still I am not able to connect what you want and how sheets are related
0
Project tracker contains the a summary of the data, in order for me to expand on the contracts data i want to continue with this on sheet two. Hence if i had a macro which would automactically copy the data from cell A to I within the project tracker to the contracts worksheet provided there is a Y in the contracts column, this will provide the basic for me to continue. I undrestand at the moment some of the cells in column M, worksheet 1 contain a Y and some other data, i believe this would have to be consistant. I hope this helps
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
May 26, 2010 at 05:21 AM
you can try below. This is based on assumption that

a. if the Project Number does not exist on Sheet Contract, the data is to be copied on the row below the last used cell in column A.

b. if the Project Number does exist on Sheet Contract, the data is to be copied over the existing data.

1. Press ALT + F11 to start VBE
2. Press CTRL + R to show Project Explorer
3. Double Click on the Sheet Project Tracker
4. Paste this code


Private Sub Worksheet_Change(ByVal Target As Range)
Dim lAtRow As Long
Dim lThisRow As Long
Dim Cell As Object

    Application.EnableEvents = False
    
    On Error GoTo Error_Handle
    
        For Each Cell In Target
        
            lThisRow = Cell.Row
            
            If ((lThisRow > 10) And (Cell.Column = 13) And (UCase(Cell) = "Y")) Then
                            
                lAtRow = 0
                
                On Error Resume Next
                
                    lAtRow = Application.WorksheetFunction.Match(Cells(lThisRow, "A"), Sheets("Contracts").Range("A:A"), 0)
                   
                On Error GoTo Error_Handle
                
                If lAtRow < 1 Then lAtRow = Sheets("Contracts").Cells(Rows.Count, "A").End(xlUp).Row + 1
                
                Sheets("Contracts").Range("A" & lAtRow & ":I" & lAtRow) = Range("A" & lThisRow & ":I" & lThisRow).Value
                
            End If
        
        Next Cell
    
END_SUB:
    
    Application.EnableEvents = True
    Exit Sub
        
Error_Handle:
    MsgBox Err.Description
    GoTo END_SUB
    
End Sub
0
It doesnt appear to work. Please note the original date will come from the project tracker, not the contracts worksheet. The contracts sheet is where i would like to data to be transferred to permanently only if the condition is met (Y in column M). Thanks
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
May 26, 2010 at 06:09 AM
It works in the sample sheet you provided. Could you post the file with the macro on the shared site with the macro
0
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
May 26, 2010 at 06:36 AM
It works. You have some lines from line 63 and down

Read the assumptions and specially assumption "A"
0
Why can i not see any data in the contracts sheet?
0