Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Putting a value in cell based on another cell

I'm trying to set a Y or N in cell Ax (based on the value in Counter)
depending on the value in cell Hx.
I wrote this using the VB help, but it errors out on "Set curCell"
Sub AddDeleteModify()
For Counter = 2 To 200
Set curCell = Worksheets("Sheet1").Cells("H" & Counter)
Set myCell = Worksheets("Sheet1").Cells("A" & Counter)
If curCell Is Nothing Then Exit Sub
If curCell = "New" Then myCell = "Y"
If curCell < "New" Then myCell = "N"
Next Counter
End Sub

Eventually, I want to add code that will start the counter over again, check
Hx and put a Y or N in Bx is depeding on whether Hx is "Delete"
Then restart the counter 1 last time and check Hx for "Modify" or
"Re-Instate ID" and put a Y in Cx if either of those values are present, and
an N if not.

Any help would be appreciated.
Also, is there a way to simply use the current worksheet, as I'm not sure
that the name of the worksheet is always going to be Sheet1?

Thank you very much for taking the time to read this.

Best regards,
Dee


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Putting a value in cell based on another cell

You can do this in a single loop. Try the below macro which works on the
activesheet

Sub AddDeleteModify()
For counter = 2 To 200
Range("A" & counter & ":C" & counter) = "N"
Select Case Range("H" & counter)
Case "New"
Range("A" & counter) = "Y"
Case "Delete"
Range("B" & counter) = "Y"
Case "Modify", "Re-Instate ID"
Range("C" & counter) = "Y"
End Select
Next counter
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Dee Sperling" wrote:

I'm trying to set a Y or N in cell Ax (based on the value in Counter)
depending on the value in cell Hx.
I wrote this using the VB help, but it errors out on "Set curCell"
Sub AddDeleteModify()
For Counter = 2 To 200
Set curCell = Worksheets("Sheet1").Cells("H" & Counter)
Set myCell = Worksheets("Sheet1").Cells("A" & Counter)
If curCell Is Nothing Then Exit Sub
If curCell = "New" Then myCell = "Y"
If curCell < "New" Then myCell = "N"
Next Counter
End Sub

Eventually, I want to add code that will start the counter over again, check
Hx and put a Y or N in Bx is depeding on whether Hx is "Delete"
Then restart the counter 1 last time and check Hx for "Modify" or
"Re-Instate ID" and put a Y in Cx if either of those values are present, and
an N if not.

Any help would be appreciated.
Also, is there a way to simply use the current worksheet, as I'm not sure
that the name of the worksheet is always going to be Sheet1?

Thank you very much for taking the time to read this.

Best regards,
Dee


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Putting a value in cell based on another cell

Hi,

Try this

Sub AddDeleteModify()
For Counter = 2 To 200
If ActiveSheet.Range("H" & Counter) = "New" Then
ActiveSheet.Range("A" & Counter).Value = "Y"
Else
ActiveSheet.Range("A" & Counter).Value = "N"
End If
Next
End Sub

Mike

"Dee Sperling" wrote:

I'm trying to set a Y or N in cell Ax (based on the value in Counter)
depending on the value in cell Hx.
I wrote this using the VB help, but it errors out on "Set curCell"
Sub AddDeleteModify()
For Counter = 2 To 200
Set curCell = Worksheets("Sheet1").Cells("H" & Counter)
Set myCell = Worksheets("Sheet1").Cells("A" & Counter)
If curCell Is Nothing Then Exit Sub
If curCell = "New" Then myCell = "Y"
If curCell < "New" Then myCell = "N"
Next Counter
End Sub

Eventually, I want to add code that will start the counter over again, check
Hx and put a Y or N in Bx is depeding on whether Hx is "Delete"
Then restart the counter 1 last time and check Hx for "Modify" or
"Re-Instate ID" and put a Y in Cx if either of those values are present, and
an N if not.

Any help would be appreciated.
Also, is there a way to simply use the current worksheet, as I'm not sure
that the name of the worksheet is always going to be Sheet1?

Thank you very much for taking the time to read this.

Best regards,
Dee


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Putting a value in cell based on another cell

Works great! Thanks so much!

"Mike H" wrote:

Hi,

Try this

Sub AddDeleteModify()
For Counter = 2 To 200
If ActiveSheet.Range("H" & Counter) = "New" Then
ActiveSheet.Range("A" & Counter).Value = "Y"
Else
ActiveSheet.Range("A" & Counter).Value = "N"
End If
Next
End Sub

Mike

"Dee Sperling" wrote:

I'm trying to set a Y or N in cell Ax (based on the value in Counter)
depending on the value in cell Hx.
I wrote this using the VB help, but it errors out on "Set curCell"
Sub AddDeleteModify()
For Counter = 2 To 200
Set curCell = Worksheets("Sheet1").Cells("H" & Counter)
Set myCell = Worksheets("Sheet1").Cells("A" & Counter)
If curCell Is Nothing Then Exit Sub
If curCell = "New" Then myCell = "Y"
If curCell < "New" Then myCell = "N"
Next Counter
End Sub

Eventually, I want to add code that will start the counter over again, check
Hx and put a Y or N in Bx is depeding on whether Hx is "Delete"
Then restart the counter 1 last time and check Hx for "Modify" or
"Re-Instate ID" and put a Y in Cx if either of those values are present, and
an N if not.

Any help would be appreciated.
Also, is there a way to simply use the current worksheet, as I'm not sure
that the name of the worksheet is always going to be Sheet1?

Thank you very much for taking the time to read this.

Best regards,
Dee


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Putting a value in cell based on another cell

Works great! Thanks so much!

"Jacob Skaria" wrote:

You can do this in a single loop. Try the below macro which works on the
activesheet

Sub AddDeleteModify()
For counter = 2 To 200
Range("A" & counter & ":C" & counter) = "N"
Select Case Range("H" & counter)
Case "New"
Range("A" & counter) = "Y"
Case "Delete"
Range("B" & counter) = "Y"
Case "Modify", "Re-Instate ID"
Range("C" & counter) = "Y"
End Select
Next counter
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Dee Sperling" wrote:

I'm trying to set a Y or N in cell Ax (based on the value in Counter)
depending on the value in cell Hx.
I wrote this using the VB help, but it errors out on "Set curCell"
Sub AddDeleteModify()
For Counter = 2 To 200
Set curCell = Worksheets("Sheet1").Cells("H" & Counter)
Set myCell = Worksheets("Sheet1").Cells("A" & Counter)
If curCell Is Nothing Then Exit Sub
If curCell = "New" Then myCell = "Y"
If curCell < "New" Then myCell = "N"
Next Counter
End Sub

Eventually, I want to add code that will start the counter over again, check
Hx and put a Y or N in Bx is depeding on whether Hx is "Delete"
Then restart the counter 1 last time and check Hx for "Modify" or
"Re-Instate ID" and put a Y in Cx if either of those values are present, and
an N if not.

Any help would be appreciated.
Also, is there a way to simply use the current worksheet, as I'm not sure
that the name of the worksheet is always going to be Sheet1?

Thank you very much for taking the time to read this.

Best regards,
Dee


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
putting one name under another on a cell HoganD87 Excel Discussion (Misc queries) 2 August 20th 07 03:04 PM
start a macro or procedure based on user putting an x in a cell mathew Excel Discussion (Misc queries) 0 August 17th 06 06:21 PM
SAP BW Report - Putting the Unit of Measure or Currency in another Cell based on Format Cell Frank & Pam Hayes[_2_] Excel Programming 1 December 3rd 05 05:38 PM
Putting Formula in Cell bw Excel Programming 2 November 2nd 05 11:23 AM
Putting text in a cell BWGames Excel Programming 2 December 30th 03 05:08 PM


All times are GMT +1. The time now is 01:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"