Hello all VBA Geniuses!
I have been lurking around on this forum for awhile, and it has been a tremendous help for me in understanding and utilizing VBA in my Excel Documents.
I have come across a situation that I am having trouble with, and cannot seem to find the answer. I hope you can help.
I have a worksheet (Sheet 7) with the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count < 1 Then Exit Sub
On Error Resume Next
Columns("A:A").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("G:G"), Unique:=True
Cells.Columns.AutoFit
End Sub
I have the following code in Sheet2:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Offset(0, -1).Value = "TOELINK" Then
On Error Resume Next
With Sheet7
With .Cells(.Rows.Count, 1).End(xlUp)(2, 1)
.Value = Target.Cells
.Offset(0, 1) = Sheet1.Range("A5").End(xlToRight)
.Offset(0, 2) = Sheet1.Range("A6").End(xlToRight)
.Offset(0, 3) = Sheet1.Range("A4").End(xlToRight)
End With
End With
End If
Cells.Columns.AutoFit
End Sub
So when I enter a value in "B2" on Sheet2, It records the target cell in "A2", and then some values from Sheet1 in the following columns.
So the current code in Sheet7 copies the unique entries from column A into column G. The last entry in column G, is the active part.
I wanted to put a condition in column H, so that the last corresponding cell would read "Active". (If there is a value in G5 and G6 is "", then H5 would show active. In addition it would make the previous entry in H now read "Obsolete" (ie: H4)
This is leading me to then trying to do some "=Sumif" operations based on the conditions in column A, D, and G.
I have tried to do both of these operations independently of one another, with no luck.
I should have prefaced this question by indicating that I am by no means a VBA programming whiz. Generally I find some code that kinda does what i want, and I can manipulate it to do what I want. Writing from scratch generally is very basic, but effective. I could probably do a better job for error handling and a host of other things, but I am generally the only one who will be using the sheets that I am creating. I have been able to do everything that i want the sheet to do, by writing equations, but I am interested in learning more about VBA, as well as keeping the workbook very tidy so other cannot "screw it up".
Anyhow, I'm down off the soapbox now. Any help is greatly appreciated.
Sorry!
Excel 2010, Windows XP
I have been lurking around on this forum for awhile, and it has been a tremendous help for me in understanding and utilizing VBA in my Excel Documents.
I have come across a situation that I am having trouble with, and cannot seem to find the answer. I hope you can help.
I have a worksheet (Sheet 7) with the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count < 1 Then Exit Sub
On Error Resume Next
Columns("A:A").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range("G:G"), Unique:=True
Cells.Columns.AutoFit
End Sub
I have the following code in Sheet2:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Offset(0, -1).Value = "TOELINK" Then
On Error Resume Next
With Sheet7
With .Cells(.Rows.Count, 1).End(xlUp)(2, 1)
.Value = Target.Cells
.Offset(0, 1) = Sheet1.Range("A5").End(xlToRight)
.Offset(0, 2) = Sheet1.Range("A6").End(xlToRight)
.Offset(0, 3) = Sheet1.Range("A4").End(xlToRight)
End With
End With
End If
Cells.Columns.AutoFit
End Sub
So when I enter a value in "B2" on Sheet2, It records the target cell in "A2", and then some values from Sheet1 in the following columns.
So the current code in Sheet7 copies the unique entries from column A into column G. The last entry in column G, is the active part.
I wanted to put a condition in column H, so that the last corresponding cell would read "Active". (If there is a value in G5 and G6 is "", then H5 would show active. In addition it would make the previous entry in H now read "Obsolete" (ie: H4)
This is leading me to then trying to do some "=Sumif" operations based on the conditions in column A, D, and G.
I have tried to do both of these operations independently of one another, with no luck.
I should have prefaced this question by indicating that I am by no means a VBA programming whiz. Generally I find some code that kinda does what i want, and I can manipulate it to do what I want. Writing from scratch generally is very basic, but effective. I could probably do a better job for error handling and a host of other things, but I am generally the only one who will be using the sheets that I am creating. I have been able to do everything that i want the sheet to do, by writing equations, but I am interested in learning more about VBA, as well as keeping the workbook very tidy so other cannot "screw it up".
Anyhow, I'm down off the soapbox now. Any help is greatly appreciated.
Sorry!
Excel 2010, Windows XP
Last edited: