Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Spreadsheets (https://www.askmehelpdesk.com/forumdisplay.php?f=395)
-   -   Can VBA do this for me? (https://www.askmehelpdesk.com/showthread.php?t=558434)

  • Feb 28, 2011, 03:15 AM
    rsdjimbie
    1 Attachment(s)
    Can VBA do this for me?
    Refer attachment;

    For sheet "SPPA" cell "D18" value to be recorded on sheet "HO plan" cell "T7", and this is where it gets nasty, as the date rolls over on the "SPPA" sheet cell "F1", so must the macro record the new value in the next cell for sheet "HO plan", ie: If "SPPA" sheet cell "F1" change to "Mon 28 Feb", then the new value must be recorded on "HO plan" cell "U7", and the same for the other colour filled cells.

    Thank you.
  • Feb 28, 2011, 02:06 PM
    JBeaucaire
    1 Attachment(s)

    This will do that:
    Code:

    Option Explicit

    Sub RecordDailyUnits()
    Dim Col As Long
    Dim LINES As Range, Ln As Range, LnFND As Range
    Dim wsHO As Worksheet

        Set wsHO = Sheets("HO plan")

        With Sheets("SPPA")
            Set LINES = .Range("A:A").SpecialCells(xlConstants)
            Col = wsHO.Cells.Find(Day(.[F1]), LookIn:=xlValues, LookAt:=xlWhole).Column
           
            For Each Ln In LINES
                Set LnFND = wsHO.Cells.Find(Ln, LookIn:=xlValues, LookAt:=xlWhole)
                Set LnFND = wsHO.Cells.Find("Booked", LnFND, LookIn:=xlValues, LookAt:=xlWhole)
                If LnFND Is Nothing Then GoTo ErrorExit
                wsHO.Cells(LnFND.Row, Col).Value = Ln.Offset(0, 3).Value
                Set LnFND = Nothing
            Next Ln
        End With
       
        Exit Sub

    ErrorExit:
        MsgBox "Could not find '" & Ln & "' on sheet HO Plan. Update sheet so there is a match."
    End Sub


    I also cleaned up some of the other macros in that wb.
  • Mar 1, 2011, 02:34 AM
    rsdjimbie
    Very cool, thank you JB!
    Where you set
    Code:

    With Sheets("SPPA")
            Set LINES = .Range("A:A").SpecialCells(xlConstants

    , do I have data which I deleted to make reading easier, the data in some cells are
    Quote:

    Profit/Loss
    ,
    Quote:

    Outwork outstanding
    and
    Quote:

    Cutting
    , when running the macro with this data in cells is macro giving me a
    Quote:

    Data mismatch
    error.
  • Mar 1, 2011, 02:57 AM
    rsdjimbie
    How do one add a new attachment when answering a question? I don't se anything here.
  • Mar 1, 2011, 06:48 PM
    JBeaucaire

    Use the GO ADVANCED button below, then the paperclip icon.
  • Mar 1, 2011, 11:04 PM
    rsdjimbie
    Comment on JBeaucaire's post
    There is no GO ADVANCED button anywhere on this page!
  • Mar 2, 2011, 04:50 AM
    JBeaucaire

    Try clicking the QUOTE button, see if that gives you the advanced editor. If not, talk to a forum moderator.
  • Mar 2, 2011, 10:37 PM
    rsdjimbie
    Comment on JBeaucaire's post
    Nothing form the QUOTE button, will talk to moderator, thank you.

  • All times are GMT -7. The time now is 01:32 AM.