writing macro

G

Guest

I have 7 collumns:
A B C D E H G
b Ptt F
b Ptt F
bb dd Ptt T
a b d Dgg T
I have 3 condition to work with:
* If column D= "Ptt" & E = "F" then copy col "B" the same row to col "H"
* If column D= "Ptt" & E = "T" then copy col "C" the same row to col "G"
* If column D= "Dgg" & E = "T" then copy col "a" the same row to col "G"

Here I have so far:
Sub ButtonCopy()
Range("B2:F20").Select
Do Until ActiveCell = ""
If ActiveCell = "" Then End
ActiveCell.Select
'ActiveCell.EntireRow.Select
If ActiveCell = "F" Then
With Selection.Interior
..ColorIndex = 6
..Pattern = xlSolid
..PatternColorIndex = xlAutomatic
Range("B2:B20").Select
Selection.Font.ColorIndex = 9
Selection.Copy
'Paste results
ActiveSheet.Paste
Range("H2:H20").Select
ActiveSheet.Paste
Selection.Font.ColorIndex = 9
End With
End If
ActiveCell.Offset(1, 0).Activate
End Sub
I Think I have couple issues on this, please help,
my question is how can I copy in the same row instead copy as range?
and can I make two condition instead of one, this is my first time writting
this, any advise will be very helpful to me.
Thanks in advance,
 
B

Bernie Deitrick

CN,

Sub ButtonCopy2()
Dim i As Integer

For i = 2 To 20
If Range("D" & i).Value = "Ptt" And _
Range("E" & i).Value = "F" Then
Range("B" & i).Copy Range("H" & i)
End If
If Range("D" & i).Value = "Ptt" And _
Range("E" & i).Value = "T" Then
Range("C" & i).Copy Range("G" & i)
End If
If Range("D" & i).Value = "Dgg" And _
Range("E" & i).Value = "T" Then
Range("A" & i).Copy Range("G" & i)
End If
Next i
End Sub

HTH,
Bernie
MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top