Log in

View Full Version : Can VBA do this for me?


rsdjimbie
Feb 28, 2011, 03:15 AM
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.

JBeaucaire
Feb 28, 2011, 02:06 PM
This will do that:

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.

rsdjimbie
Mar 1, 2011, 02:34 AM
Very cool, thank you JB!
Where you set
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
Profit/Loss,
Outwork outstandingand
Cutting, when running the macro with this data in cells is macro giving me a
Data mismatcherror.

rsdjimbie
Mar 1, 2011, 02:57 AM
How do one add a new attachment when answering a question? I don't se anything here.

JBeaucaire
Mar 1, 2011, 06:48 PM
Use the GO ADVANCED button below, then the paperclip icon.

rsdjimbie
Mar 1, 2011, 11:04 PM
There is no GO ADVANCED button anywhere on this page!

JBeaucaire
Mar 2, 2011, 04:50 AM
Try clicking the QUOTE button, see if that gives you the advanced editor. If not, talk to a forum moderator.

rsdjimbie
Mar 2, 2011, 10:37 PM
Nothing form the QUOTE button, will talk to moderator, thank you.