Hi,
Please could someone advise me on how to do the following. I am creating a task tracker to help me keep track of jobs. I would like it so that i can keep adding updates to the task until it is complete. The problem is i would like to be able to see the latest update without scrolling right all the time.
Is there some VBA that i can put in so that when i add an update in column k (attached) it auto moves the comments to the right one cell.
This would then mean that i can see the latest update without scrolling accross and only when i need to will i have to check the previous updates.
Any help would be appreciated. Thanks in advance.
Chemist
Last edited by Chemistification; 08-18-2011 at 08:40 AM. Reason: Problem sloved
Hi,
I assume that after you enter a new value in column K and after the other comments have been shifted over one cell you want that value to be copied across to the now blank cell on the right. If not just leave out the second line in the code below which should be entered at the end of the Sheet Change event.
If Not Intersect(Target, Range("K6:K1000")) Is Nothing Then Target.Cells(1, 2).Insert Shift:=xlToRight Target.Copy Destination:=Target.Cells(1, 2) End If
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
Hi richard,
Thanks for taking the time to answer my question. I am having trouble entering the code into the macro that is already in there. In the macro that is already in there it finishes with
End With
Target.EntireRow.Delete
I have tried adding the code after that bit (then press alt + Q to save) however i cant get it to work. I must confessi do know very little about VBA.
Hi,
Put it immediately before your main IF..End IF block.
Regards
Last edited by Richard Buttrey; 08-17-2011 at 07:38 AM.
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
Hi Richard. Thanks again. Am i right in thinking i just cut and paste it before the main If block? If so then i still can't get it to work. I have it looking like:
Private Sub Worksheet_Change(ByVal Target As Range) Dim sColumn As String Dim lNextRow As Long Dim shTo As Worksheet Dim r As Range '******************************** 'Change these to the correct values sColumn = "J" Set shTo = Worksheets("Open Tasks") '******************************** If Not Intersect(Target, Range("K6:K1000")) Is Nothing Then Target.Cells(1, 2).Insert Shift:=xlToRight Target.Copy Destination:=Target.Cells(1, 2) End If If Target.Count = 1 Then Set r = Target.Worksheet.Columns(sColumn & ":" & sColumn) If Not Intersect(Target, r) Is Nothing Then If Target.Value = "O" Then With shTo lNextRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1 Target.EntireRow.Copy .Range("A" & lNextRow).EntireRow End With Target.EntireRow.Delete End If End If End If End Sub
Ah okay. I worked out where i was going wrong. I was working on the wrong worksheet. oops. Thanks to Richard for all your help with this. It's really appreciated.
One last thing that would make it even better. When it moves the text over to the right it still leaves the origional text in column K. Is there anyway to modify this so that when the text moves over column K becomes blank again?
Many thanks
Chemist
Hi,
Yes that's the right place to put it. Are you sure you've added it to the sheet change event of the 'Open Tasks' sheet and not the 'Closed Tasks' sheet?
Here's a slight modification. It doesn't affect what I originally gave you which should run OK, but it just stops the macro using the IF test a second time when the entry is copied to the adjacent cell.
If Not Intersect(Target, Range("K6:K1000")) Is Nothing Then Application.EnableEvents = False Target.Cells(1, 2).Insert Shift:=xlToRight Target.Copy Destination:=Target.Cells(1, 2) Application.EnableEvents = True End If
Last edited by Richard Buttrey; 08-17-2011 at 09:50 AM.
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
Hi, just add Target = "" as the penultimate line. i.e.
RegardsIf Not Intersect(Target, Range("K6:K1000")) Is Nothing Then Application.EnableEvents = False Target.Cells(1, 2).Insert Shift:=xlToRight Target.Copy Destination:=Target.Cells(1, 2) Target = "" Application.EnableEvents = True End If
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
Yes you called it correct. I was putting it in the closed task sheet. Obvious now but frustrating when i couldnt get it too work. Any idea on how i odify the code to keep the cell in column K blank after it has copied accross?
Sorry didn't see the above.
Thanks for your help with this
Last edited by Chemistification; 08-17-2011 at 10:03 AM.
Hi,
I am not sure if this should be a new post. If it is please let me know and i will start a new thread.
The inclusion of the code to make the data move to the right seems to be impacting on my original code. Now when i try using the original code it comes up with errors. Is there an obvious reason why from looking at the below?
I have attached a copy of the spreadsheet as well.
Private Sub Worksheet_Change(ByVal Target As Range) Dim sColumn As String Dim lNextRow As Long Dim shTo As Worksheet Dim r As Range '******************************** 'Change these to the correct values sColumn = "J" Set shTo = Worksheets("Closed Tasks") '******************************** If Not Intersect(Target, Range("K6:K1000")) Is Nothing Then Application.EnableEvents = False Target.Cells(1, 2).Insert Shift:=xlToRight Target.Copy Destination:=Target.Cells(1, 2) Target = "" Application.EnableEvents = True End If If Target.Count = 1 Then Set r = Target.Worksheet.Columns(sColumn & ":" & sColumn) If Not Intersect(Target, r) Is Nothing Then If Target.Value = "C" Then With shTo lNextRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1 Target.EntireRow.Copy .Range("A" & lNextRow).EntireRow End With Target.EntireRow.Delete End If End If End If End Sub
Does anyone know why i would be getting a run time error 1004 with the above script. It has two functions. One moves shifts data to the right one column when it is entered into column K
The other moves the entire row to the closed tab when column J is set to C. Both work independently of each other but not when combined. The columns are the same in the closed tab as the open.
When i go to debug it highlights the following line:
Any ideas? Again if this needs to be a new thread please let me know.Target.Copy Destination:=Target.Cells(1, 2)
Edit: Also noted that deleting a row throws up the same error. It also knocks the whole row out of line by 1 column to the right?
Last edited by Chemistification; 08-18-2011 at 06:37 AM.
Hi,
It seems to work OK for me. I'm pasting the whole code below since I've added the two Application.EnableEvents True/False lines in the second main IF.
Also you should delete the code in the 'Closed Tasks' sheet change event. It's redundant since everything is driven by the 'Open Tasks' sheet change event.
Private Sub Worksheet_Change(ByVal Target As Range) Dim sColumn As String Dim lNextRow As Long Dim shTo As Worksheet Dim r As Range '******************************** 'Change these to the correct values sColumn = "J" Set shTo = Worksheets("Closed Tasks") '******************************** If Not Intersect(Target, Range("K6:K1000")) Is Nothing Then Application.EnableEvents = False Target.Cells(1, 2).Insert Shift:=xlToRight Target.Copy Destination:=Target.Cells(1, 2) Target = "" Application.EnableEvents = True End If If Target.Count = 1 Then Set r = Target.Worksheet.Columns(sColumn & ":" & sColumn) If Not Intersect(Target, r) Is Nothing Then Application.EnableEvents = False If Target.Value = "C" Then With shTo lNextRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1 Target.EntireRow.Copy .Range("A" & lNextRow).EntireRow End With Target.EntireRow.Delete End If End If Application.EnableEvents = True End If End Sub
Richard Buttrey
If this was useful then please rate it appropriately.
Click the small star iconat the bottom left of my post.
Cheers Richard. Works beautifully. Thanks for all the help over two days. I am really pleased with the outcome and couldn't have done it on my own. Should hopefully keep me a bit more organised.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks