Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
If Then Statement
I have the following Visual Basic Sub in an excel 2000
worksheet: If Worksheets(1).Range("J2").Value = "RT" Then Worksheets (1).Range("BG2").Value = "RT" This works fine. What I want to do is for this to work for every cell in column "J" and every cell in column "BG" Not just J2 and BG2. I have thousands of records so it is not possible to type this expression for each cell number. Any advice would be awesome and appreciated. thanks so much, matthew. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
If Then Statement
This is drastic but it works:
Range("J:J").Value = Range("BG:BG").Value Geof. -----Original Message----- I have the following Visual Basic Sub in an excel 2000 worksheet: If Worksheets(1).Range("J2").Value = "RT" Then Worksheets (1).Range("BG2").Value = "RT" This works fine. What I want to do is for this to work for every cell in column "J" and every cell in column "BG" Not just J2 and BG2. I have thousands of records so it is not possible to type this expression for each cell number. Any advice would be awesome and appreciated. thanks so much, matthew. . |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
If Then Statement
Dim cRows As Long
cRows = Cells(Rows.Count,"J").End(xlUp).Row With Worksheets(1) For i = 2 To cRows If .Range("J" & i).Value = "RT" Then .Range("BG" & i).Value = "RT" Next i End With -- HTH RP "matthew" wrote in message ... I have the following Visual Basic Sub in an excel 2000 worksheet: If Worksheets(1).Range("J2").Value = "RT" Then Worksheets (1).Range("BG2").Value = "RT" This works fine. What I want to do is for this to work for every cell in column "J" and every cell in column "BG" Not just J2 and BG2. I have thousands of records so it is not possible to type this expression for each cell number. Any advice would be awesome and appreciated. thanks so much, matthew. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
If Then Statement
Here is how you would loop though every row:
Sub Macro1() Dim lastrow As Long Dim currentrow As Long lastrow = Worksheets(1).UsedRange.Row + _ Worksheets(1).UsedRange.Rows.Count For currentrow = 1 To lastrow Step 1 If Worksheets(1).Range("J" & currentrow).Value = "RT" Then Worksheets(1).Range("BG" & currentrow).Value = "RT" End If Next currentrow End Sub Hope this helps, Kris -----Original Message----- I have the following Visual Basic Sub in an excel 2000 worksheet: If Worksheets(1).Range("J2").Value = "RT" Then Worksheets (1).Range("BG2").Value = "RT" This works fine. What I want to do is for this to work for every cell in column "J" and every cell in column "BG" Not just J2 and BG2. I have thousands of records so it is not possible to type this expression for each cell number. Any advice would be awesome and appreciated. thanks so much, matthew. . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Vlookup, if statement, maybe an and statement | Excel Discussion (Misc queries) | |||
IF statement inside a SUMIF statement.... or alternative method | Excel Worksheet Functions | |||
Reconcile Bank statement & Credit card statement & accounting data | Excel Worksheet Functions | |||
Embedding an OR statement in an IF statement efficiently | Excel Discussion (Misc queries) | |||
appending and IF statement to an existing IF statement | Excel Worksheet Functions |