ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   writing macro (https://www.excelbanter.com/new-users-excel/38287-writing-macro.html)

CN

writing macro
 
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,

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


"CN" wrote in message
...
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,




CN

Thank you very much for helping, it works great!
..
CN

"Bernie Deitrick" wrote:

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


"CN" wrote in message
...
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,






All times are GMT +1. The time now is 02:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com