Consulting

Results 1 to 11 of 11

Thread: Solved: Point me in the right direction please

  1. #1
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,072
    Location

    Solved: Point me in the right direction please

    I have a simple spreadsheet to record the Electrical work issues (jobs) for the contractor who is hard to get to complete jobs. The concept here is enable users to enter details of job requests into the spreadsheet such as Raised Date, Electrical Work issue, Priority rating, Discussed (Y/N),Quote required (Y/N), Action Date & Completed (Y/N). The object here is to have the jobs listed, and when completed enter a "Yes value in the "H" Column, which then clears the row from the "Outstanding Work" sheet to the "Completed Work" sheet.

    Well that's the theory...

    Anyhow I plagurised some code from another spreadsheet and came up with this.

    [vba]

    Private Sub Worksheet_Change(By Val Target As Range)
    ' Written 19/07/06 by Ted Eggleston
    'Copy and Paste "Yes" row to Completed Work Sheet
    If Target.Cells.Count >1 Then Exit Sub
    Application.ScreenUpdating = False
    Application.EnableEvents = False

    If Target.Column = 8 and Target.Row >1 And Target = "Yes" Then
    lRow = Sheets("Completed Work").Cells(Row.Count, 1).End (xlUp).Offset_ (1).Row
    With ActiveSheet
    .Range(.Cells(Target.Row, 1), .Cells(Target.Row, 8))).Copy
    With Sheets("Completed Work")
    .Range(.Cells(lRow, 1), .Cells(lRow, 8).PasteSpecial xlValues
    End With

    ' Reset default values for the row just copied
    cRow = Target.Row
    .Range("A" &cRow & ":H" & cRow). ClearContents
    End With

    End If
    Application.ScreenUpdating = True
    Application.EnableEvents = True

    End Sub

    [/vba]

    Am I even in the same ball park as the concept? When the value in cell "H" changes from No to Yes, I would like that row to be copied to the second sheet and ... then the initial row copied to be cleared. On trying this section of code I am greeted with a procedure to create a macro, which I wanted to call "Completed_Work". And then I came really unstuck...

    It wants me to fill in some more code. What goes in here?

    Back on the main sheet I now have an empty row. Can I move the rows up to fill the gap without having to use the Cut & Paste mode?

    Ted
    Last edited by Killian; 07-19-2006 at 07:32 AM. Reason: fix VBA tags

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Haven't looked at this too closely yet but why do you have this code in the Thisworkbook module?
    [VBA]
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Address = "$H$2" And Target = "Yes" Then

    ActiveSheet.Range("A2:H2").Copy
    Sheets("CompletedWork").Range("A" & lRow).PasteSpecial xlPasteValues

    Application.CutCopyMode = False

    'Reset the values in the row just copied
    ActiveSheet.Range("A2:H2").ClearContents
    End If
    End Sub
    [/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,072
    Location
    Where should it be?

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hey Aussie,
    I got this working but I had to delete your "Completed Work" sheet. I then copied the Outstanding work sheet and renamed it to Completed work and it works fine now. Seems formatting must be identical for this to work.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,072
    Location
    Thank you Steve. Will try this at work to see if this meets their needs. It gets me out of some considerable trouble with work.

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]With Sheets("Completed Work")
    .Range(.Cells(lRow, 1), .Cells(lRow, 8).PasteSpecial xlValues
    End With
    [/VBA]
    Why go to the trouble of setting the destination range, when the top left cell will suffice? If you change your copy size, then the paste may fail.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,072
    Location
    Quote Originally Posted by mdmackillop
    Why go to the trouble of setting the destination range, when the top left cell will suffice? If you change your copy size, then the paste may fail.
    Regards
    MD
    Malcolm, its me your talking to. No double speak please. You need to bear in mind that I'm "mentally", and "age" challenged.

    What I took to work to day, refused point blank to work. Mind you I left work red faced and super frustrated.... I need a drink.


    BTW. Keep them coming....

    OKay whiz kids, if I shorten the size of a sheet ( anything right of Column I and anything below Row 500 do I cause the system to hyperventilate?

    Ted
    Last edited by Aussiebear; 07-20-2006 at 12:48 AM. Reason: An after the event thought

  8. #8
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Quote Originally Posted by mdmackillop
    Why go to the trouble of setting the destination range, when the top left cell will suffice? If you change your copy size, then the paste may fail.
    Regards
    MD
    What Malcolm is talking about is how paste works in Excel. Try it manually: copy a range of cells, then select a single cell in another location and paste. You don't need to select the same number of cells as you copied - you just select the top left cell. You are much more likely to generate an error if you try to select the correct number of cells prior to pasting.

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks GG
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,072
    Location
    Thanks GG, my problem is that I'm so tired form the long consistant hours at work that I'm mentally stuffed. I'm averaging 4 hours sleep a night and its becoming a struggle to survive. Could someone plese tell me in very plain language, the who what when and where for the spreadsheet I'm working on.

    I don't care if you break it down to the A is for apple, b for bat, c for cat style. I am so tired anything looks good right now.

    Ted

  11. #11
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,072
    Location
    Okay slept on this. I understand that which Malcolm is saying,

Posting Permissions

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