Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the Value of one cell to deterime another 1

Status
Not open for further replies.

LGMan

MIS
Aug 27, 2003
233
GB
Hi, i'm trying to get a piece of code working that looks for the Cell.Value of Cells range D2:D25 for a value of "R ". If so then the corresponding cell in Column E should say "Paid"
My code will only work for E2 and then stop and I don't know enough to know why. I'd usually look in my vba book, but the book is at home and I'm not :-(
Any help greatly appreciated

Code:
 Dim Cell As Range
     
Range("D2:D25").Select
        For Each Cell In Selection
        If Cell.Value = "R  " Then ActiveCell.Offset(0, 1).Value = "Paid"
 Next Cell
 


hi,

Why not a simply spreadsheet formula???

No VBA is required to accomplish what you have described.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip, I should have said that I'll be doing similar on at least 16 columns, so wanted to just have the code stored in a macro and assign it to a button.
Also things have gotten more complicated as I've scanned the other columns as now I only need the code to run if for example to cell values in col E are blank.
 
Code:
Dim r As Range
  'assuming that there is data in every cell in the range in column D.
  'this code will process no matter how many rows you have
 
   For Each r In Range(cells(2,"D"), cells(2,"D").end(xldown))
      If r.Value = "R  " Then r.Offset(0, 1).Value = "Paid"
   Next

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks Skip.
is it possible to tweek your code so that it skips any cell in Col B that already has a value?
 
Sorry, have sorted it now
Code:
Dim r As Range
  'assuming that there is data in every cell in the range in column D.
  'this code will process no matter how many rows you have
 
   For Each r In Range(Cells(2, "D"), Cells(2, "D").End(xlDown))
      If r.Value = "R  " And r.Offset(0, 1).Value = "" Then r.Offset(0, 1).Value = "R  "
   Next
Many thanks for pointing me in the right direction
 


r.Offset(0, 1) does NOT refer to column B in your example!

Rather, it refers to column E.

And why would you not code...
Code:
  If r.Value = "R  " And r.Offset(0, 1).Value = "" Then r.Offset(0, 1).Value = r.value
And furthermore...
Code:
   For Each r In Range(Cells(2, "D"), Cells(2, "D").End(xlDown))
     with r
      If .Value = "R  " And .Offset(0, 1).Value = "" Then .Offset(0, 1).Value = .value
     end with
   Next

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Cheers Skip, you're a star, when all I've done is type some cr*p. It is Col E that can have existing data rather than B as I had typed. My mistake and my mistake again for not checking before posting.
In my code I had made the value to input to col E as "R " simply to easily see that my change worked as it should.
I posted back my code as it stood in a effort to get up there as quickly as I could and hoping to save you from replying.
Have now changed the string to "paid" but I take away your final piece of code as no doubt I'll find a use for it soon. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top