PC Review


Reply
Thread Tools Rate Thread

After checked condition, add the data to adjacent cell automatically

 
 
tlee
Guest
Posts: n/a
 
      20th May 2009
Hi all,

Could anyone help me how to check condition, and fill the data to the
adjacent cell automatically?

Such that, there are several columns at the worksheet.

And I specified to use 2 columns (C and D) only.

Column D contains characters in each cell.
Column C is blank Column without data in all cell.

It checks the number of the characters in each cell of column D.
If the number of characters is 10 in D2, then fill "5" into C2
If the number of characters is 20 in D3, then fill "4" into C3

How can I implement that operation?

Thanks for your in advance.

TLee




 
Reply With Quote
 
 
 
 
AltaEgo
Guest
Posts: n/a
 
      20th May 2009
You may need to fiddle the numbers but, this should give you the idea:

=IF(LEN(D1)<10,5,IF(LEN(D1)<20,4,IF(LEN(D1)<30,3,IF(LEN(D1)<40,2,IF(LEN(D1)>=40,1)))))

OK, that's a lot to take on board in one hit so let's go at it step-by-step:

The Syntax for If()

=IF(condition, If TRUE, If FALSE)

Add the condition:

=IF(LEN(D1)<10, If TRUE, If FALSE)


Now add the If TRUE part

=IF(LEN(D1)<10,5, If FALSE)

Now add the if FALSE part (which is another If() statement, until the last
nested IF when you use a value)

=IF(LEN(D1)<10,5, IF(condition, If TRUE, If FALSE))

Keep building replacing your condition, true and false parts until you cover
all conditions. There is a limit of seven nested Ifs.





--
Steve

"tlee" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> Hi all,
>
> Could anyone help me how to check condition, and fill the data to the
> adjacent cell automatically?
>
> Such that, there are several columns at the worksheet.
>
> And I specified to use 2 columns (C and D) only.
>
> Column D contains characters in each cell.
> Column C is blank Column without data in all cell.
>
> It checks the number of the characters in each cell of column D.
> If the number of characters is 10 in D2, then fill "5" into C2
> If the number of characters is 20 in D3, then fill "4" into C3
>
> How can I implement that operation?
>
> Thanks for your in advance.
>
> TLee
>
>
>
>

 
Reply With Quote
 
AltaEgo
Guest
Posts: n/a
 
      20th May 2009
Sorry. I just noticed that you want to automate the process with code rather
than use a function.

Sub Test()
' Select column D cells
' Results show in Column C
For Each c In Selection

x = Len(c)

Select Case x

Case Is < 10
rtn = 5
Case Is < 20
rtn = 4
Case Is < 30
rtn = 3
Case Is < 40
rtn = 2
Case Is < 50
rtn = 1
Case Else
rtn = 0

End Select

c.Offset(, -1) = rtn

Next c
End Sub

--
Steve

"tlee" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> Hi all,
>
> Could anyone help me how to check condition, and fill the data to the
> adjacent cell automatically?
>
> Such that, there are several columns at the worksheet.
>
> And I specified to use 2 columns (C and D) only.
>
> Column D contains characters in each cell.
> Column C is blank Column without data in all cell.
>
> It checks the number of the characters in each cell of column D.
> If the number of characters is 10 in D2, then fill "5" into C2
> If the number of characters is 20 in D3, then fill "4" into C3
>
> How can I implement that operation?
>
> Thanks for your in advance.
>
> TLee
>
>
>
>

 
Reply With Quote
 
tlee
Guest
Posts: n/a
 
      20th May 2009
Hi AltaEgo,

Thanks for your help. You give me the idea how to implement the macro.

Besides, anyone know how to selected the specified column pattern for
checking?

Such that, check column (B, D, F, H, J, L,........) in the worksheet.

I tried to find information about it. It is more likely to use
"range.Offset( )" to implement.

Am I correct? how can I loop it until checked all specified columns.

Thanks for your in advance.

Best regards,
Tom Lee



> Sorry. I just noticed that you want to automate the process with code
> rather than use a function.
>
> Sub Test()
> ' Select column D cells
> ' Results show in Column C
> For Each c In Selection
>
> x = Len(c)
>
> Select Case x
>
> Case Is < 10
> rtn = 5
> Case Is < 20
> rtn = 4
> Case Is < 30
> rtn = 3
> Case Is < 40
> rtn = 2
> Case Is < 50
> rtn = 1
> Case Else
> rtn = 0
>
> End Select
>
> c.Offset(, -1) = rtn
>
> Next c
> End Sub
>
> --
> Steve
>
> "tlee" <(E-Mail Removed)> wrote in message
> news:#(E-Mail Removed)...
>> Hi all,
>>
>> Could anyone help me how to check condition, and fill the data to the
>> adjacent cell automatically?
>>
>> Such that, there are several columns at the worksheet.
>>
>> And I specified to use 2 columns (C and D) only.
>>
>> Column D contains characters in each cell.
>> Column C is blank Column without data in all cell.
>>
>> It checks the number of the characters in each cell of column D.
>> If the number of characters is 10 in D2, then fill "5" into C2
>> If the number of characters is 20 in D3, then fill "4" into C3
>>
>> How can I implement that operation?
>>
>> Thanks for your in advance.
>>
>> TLee
>>
>>
>>
>>

 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      20th May 2009
Option Explicit

Sub demo()

manager "C"

End Sub

Sub manager(col As String)
Dim source As Range
Dim cell As Range

Set source = Columns(col).SpecialCells(xlCellTypeConstants)
If Not source Is Nothing Then
For Each cell In source.Cells
Select Case Len(cell.Value)
Case 10
cell.Offset(, 1).Value = 5
Case 20
cell.Offset(, 1).Value = 4
Case Else
End Select

Next

End If


End Sub


"tlee" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> Hi all,
>
> Could anyone help me how to check condition, and fill the data to the
> adjacent cell automatically?
>
> Such that, there are several columns at the worksheet.
>
> And I specified to use 2 columns (C and D) only.
>
> Column D contains characters in each cell.
> Column C is blank Column without data in all cell.
>
> It checks the number of the characters in each cell of column D.
> If the number of characters is 10 in D2, then fill "5" into C2
> If the number of characters is 20 in D3, then fill "4" into C3
>
> How can I implement that operation?
>
> Thanks for your in advance.
>
> TLee
>
>
>
>

 
Reply With Quote
 
AltaEgo
Guest
Posts: n/a
 
      20th May 2009
List your columns in an array. Call the other (slightly modified code) for
each element of the array.

Sub Test()
Dim i, ArrCols

ArrCols = Array("D", "F", "H", "J") 'etc
For i = LBound(ArrCols) To UBound(ArrCols)

Call LenCheck(ArrCols(i))

Next i

End Sub

Sub LenCheck(Col)
dim c,x
Range(Col & "2").Select
Range(Selection, Selection.End(xlDown)).Select

For Each c In Selection

x = Len(c)

Select Case x

Case Is < 10
rtn = 5
Case Is < 20
rtn = 4
Case Is < 30
rtn = 3
Case Is < 40
rtn = 2
Case Is < 50
rtn = 1
Case Else
rtn = 0

End Select

c.Offset(, -1) = rtn

Next c
End Sub


Depending how many you need to do, selecting and looping each cell may be
slow.

--
Steve

"tlee" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> Hi AltaEgo,
>
> Thanks for your help. You give me the idea how to implement the macro.
>
> Besides, anyone know how to selected the specified column pattern for
> checking?
>
> Such that, check column (B, D, F, H, J, L,........) in the worksheet.
>
> I tried to find information about it. It is more likely to use
> "range.Offset( )" to implement.
>
> Am I correct? how can I loop it until checked all specified columns.
>
> Thanks for your in advance.
>
> Best regards,
> Tom Lee
>
>
>
>> Sorry. I just noticed that you want to automate the process with code
>> rather than use a function.
>>
>> Sub Test()
>> ' Select column D cells
>> ' Results show in Column C
>> For Each c In Selection
>>
>> x = Len(c)
>>
>> Select Case x
>>
>> Case Is < 10
>> rtn = 5
>> Case Is < 20
>> rtn = 4
>> Case Is < 30
>> rtn = 3
>> Case Is < 40
>> rtn = 2
>> Case Is < 50
>> rtn = 1
>> Case Else
>> rtn = 0
>>
>> End Select
>>
>> c.Offset(, -1) = rtn
>>
>> Next c
>> End Sub
>>
>> --
>> Steve
>>
>> "tlee" <(E-Mail Removed)> wrote in message
>> news:#(E-Mail Removed)...
>>> Hi all,
>>>
>>> Could anyone help me how to check condition, and fill the data to the
>>> adjacent cell automatically?
>>>
>>> Such that, there are several columns at the worksheet.
>>>
>>> And I specified to use 2 columns (C and D) only.
>>>
>>> Column D contains characters in each cell.
>>> Column C is blank Column without data in all cell.
>>>
>>> It checks the number of the characters in each cell of column D.
>>> If the number of characters is 10 in D2, then fill "5" into C2
>>> If the number of characters is 20 in D3, then fill "4" into C3
>>>
>>> How can I implement that operation?
>>>
>>> Thanks for your in advance.
>>>
>>> TLee
>>>
>>>
>>>
>>>

 
Reply With Quote
 
tlee
Guest
Posts: n/a
 
      22nd May 2009
Thank you all

Tlee


> Option Explicit
>
> Sub demo()
>
> manager "C"
>
> End Sub
>
> Sub manager(col As String)
> Dim source As Range
> Dim cell As Range
>
> Set source = Columns(col).SpecialCells(xlCellTypeConstants)
> If Not source Is Nothing Then
> For Each cell In source.Cells
> Select Case Len(cell.Value)
> Case 10
> cell.Offset(, 1).Value = 5
> Case 20
> cell.Offset(, 1).Value = 4
> Case Else
> End Select
>
> Next
>
> End If
>
>
> End Sub
>
>
> "tlee" <(E-Mail Removed)> wrote in message
> news:#(E-Mail Removed)...
>> Hi all,
>>
>> Could anyone help me how to check condition, and fill the data to the
>> adjacent cell automatically?
>>
>> Such that, there are several columns at the worksheet.
>>
>> And I specified to use 2 columns (C and D) only.
>>
>> Column D contains characters in each cell.
>> Column C is blank Column without data in all cell.
>>
>> It checks the number of the characters in each cell of column D.
>> If the number of characters is 10 in D2, then fill "5" into C2
>> If the number of characters is 20 in D3, then fill "4" into C3
>>
>> How can I implement that operation?
>>
>> Thanks for your in advance.
>>
>> TLee
>>
>>
>>
>>

 
Reply With Quote
 
tlee
Guest
Posts: n/a
 
      25th May 2009
Hi Steve,

Could you help to explain the following 2 statements?

Range(Col & "2").Select
Range(Selection, Selection.End(xlDown)).Select

Thanks,
Tlee



> List your columns in an array. Call the other (slightly modified code) for
> each element of the array.
>
> Sub Test()
> Dim i, ArrCols
>
> ArrCols = Array("D", "F", "H", "J") 'etc
> For i = LBound(ArrCols) To UBound(ArrCols)
>
> Call LenCheck(ArrCols(i))
>
> Next i
>
> End Sub
>
> Sub LenCheck(Col)
> dim c,x
> Range(Col & "2").Select
> Range(Selection, Selection.End(xlDown)).Select
>
> For Each c In Selection
>
> x = Len(c)
>
> Select Case x
>
> Case Is < 10
> rtn = 5
> Case Is < 20
> rtn = 4
> Case Is < 30
> rtn = 3
> Case Is < 40
> rtn = 2
> Case Is < 50
> rtn = 1
> Case Else
> rtn = 0
>
> End Select
>
> c.Offset(, -1) = rtn
>
> Next c
> End Sub
>
>
> Depending how many you need to do, selecting and looping each cell may be
> slow.
>
> --
> Steve
>
> "tlee" <(E-Mail Removed)> wrote in message
> news:#(E-Mail Removed)...
>> Hi AltaEgo,
>>
>> Thanks for your help. You give me the idea how to implement the macro.
>>
>> Besides, anyone know how to selected the specified column pattern for
>> checking?
>>
>> Such that, check column (B, D, F, H, J, L,........) in the worksheet.
>>
>> I tried to find information about it. It is more likely to use
>> "range.Offset( )" to implement.
>>
>> Am I correct? how can I loop it until checked all specified columns.
>>
>> Thanks for your in advance.
>>
>> Best regards,
>> Tom Lee
>>
>>
>>
>>> Sorry. I just noticed that you want to automate the process with code
>>> rather than use a function.
>>>
>>> Sub Test()
>>> ' Select column D cells
>>> ' Results show in Column C
>>> For Each c In Selection
>>>
>>> x = Len(c)
>>>
>>> Select Case x
>>>
>>> Case Is < 10
>>> rtn = 5
>>> Case Is < 20
>>> rtn = 4
>>> Case Is < 30
>>> rtn = 3
>>> Case Is < 40
>>> rtn = 2
>>> Case Is < 50
>>> rtn = 1
>>> Case Else
>>> rtn = 0
>>>
>>> End Select
>>>
>>> c.Offset(, -1) = rtn
>>>
>>> Next c
>>> End Sub
>>>
>>> --
>>> Steve
>>>
>>> "tlee" <(E-Mail Removed)> wrote in message
>>> news:#(E-Mail Removed)...
>>>> Hi all,
>>>>
>>>> Could anyone help me how to check condition, and fill the data to the
>>>> adjacent cell automatically?
>>>>
>>>> Such that, there are several columns at the worksheet.
>>>>
>>>> And I specified to use 2 columns (C and D) only.
>>>>
>>>> Column D contains characters in each cell.
>>>> Column C is blank Column without data in all cell.
>>>>
>>>> It checks the number of the characters in each cell of column D.
>>>> If the number of characters is 10 in D2, then fill "5" into C2
>>>> If the number of characters is 20 in D3, then fill "4" into C3
>>>>
>>>> How can I implement that operation?
>>>>
>>>> Thanks for your in advance.
>>>>
>>>> TLee
>>>>
>>>>
>>>>
>>>>

 
Reply With Quote
 
AltaEgo
Guest
Posts: n/a
 
      25th May 2009
The Test() Sub is an array of the columns you wish to check. It calls them
one-by-one passing the value to LenCheck through the parameter named 'Col'.


So, for each of the columns listed in the array, LenCheck runs:

Range(Col & "2").Select

For example, if D is passed from the array, the above can be read as
Range("D2").select

Or, the same as click on Cell D2.

Range(Selection, Selection.End(xlDown)).Select

Selects all cells from the current selection (D2 in the example) to the cell
above the next blank cell in the column, moving down.

Or, the same as holding the [Shift] key and pressing [End]/[Down arrow]

Note
Range(Selection, Selection.End(xlDown)).Select assumes there are no blank
rows in the area you wish to check. If you are having problems because of
blank rows substitute:

'select last cell in row
Range(Col & "65536").Select
'move selection up to last cell with a value
Selection.End(xlUp).Select.
'select from that point to the row 2 cell
Range(Selection, Range(Col & "2")).Select


in place of

Range(Col & "2").Select
Range(Selection, Selection.End(xlDown)).Select

The choice you make depends on data and layout. If you have summary below,
you need the original code and a blank row between data area and summary. If
you have summary in a different area, and may encounter blank rows, use the
substitute.


--
Steve

"tlee" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> Hi Steve,
>
> Could you help to explain the following 2 statements?
>
> Range(Col & "2").Select
> Range(Selection, Selection.End(xlDown)).Select
>
> Thanks,
> Tlee
>
>
>
>> List your columns in an array. Call the other (slightly modified code)
>> for each element of the array.
>>
>> Sub Test()
>> Dim i, ArrCols
>>
>> ArrCols = Array("D", "F", "H", "J") 'etc
>> For i = LBound(ArrCols) To UBound(ArrCols)
>>
>> Call LenCheck(ArrCols(i))
>>
>> Next i
>>
>> End Sub
>>
>> Sub LenCheck(Col)
>> dim c,x
>> Range(Col & "2").Select
>> Range(Selection, Selection.End(xlDown)).Select
>>
>> For Each c In Selection
>>
>> x = Len(c)
>>
>> Select Case x
>>
>> Case Is < 10
>> rtn = 5
>> Case Is < 20
>> rtn = 4
>> Case Is < 30
>> rtn = 3
>> Case Is < 40
>> rtn = 2
>> Case Is < 50
>> rtn = 1
>> Case Else
>> rtn = 0
>>
>> End Select
>>
>> c.Offset(, -1) = rtn
>>
>> Next c
>> End Sub
>>
>>
>> Depending how many you need to do, selecting and looping each cell may be
>> slow.
>>
>> --
>> Steve
>>
>> "tlee" <(E-Mail Removed)> wrote in message
>> news:#(E-Mail Removed)...
>>> Hi AltaEgo,
>>>
>>> Thanks for your help. You give me the idea how to implement the macro.
>>>
>>> Besides, anyone know how to selected the specified column pattern for
>>> checking?
>>>
>>> Such that, check column (B, D, F, H, J, L,........) in the worksheet.
>>>
>>> I tried to find information about it. It is more likely to use
>>> "range.Offset( )" to implement.
>>>
>>> Am I correct? how can I loop it until checked all specified columns.
>>>
>>> Thanks for your in advance.
>>>
>>> Best regards,
>>> Tom Lee
>>>
>>>
>>>
>>>> Sorry. I just noticed that you want to automate the process with code
>>>> rather than use a function.
>>>>
>>>> Sub Test()
>>>> ' Select column D cells
>>>> ' Results show in Column C
>>>> For Each c In Selection
>>>>
>>>> x = Len(c)
>>>>
>>>> Select Case x
>>>>
>>>> Case Is < 10
>>>> rtn = 5
>>>> Case Is < 20
>>>> rtn = 4
>>>> Case Is < 30
>>>> rtn = 3
>>>> Case Is < 40
>>>> rtn = 2
>>>> Case Is < 50
>>>> rtn = 1
>>>> Case Else
>>>> rtn = 0
>>>>
>>>> End Select
>>>>
>>>> c.Offset(, -1) = rtn
>>>>
>>>> Next c
>>>> End Sub
>>>>
>>>> --
>>>> Steve
>>>>
>>>> "tlee" <(E-Mail Removed)> wrote in message
>>>> news:#(E-Mail Removed)...
>>>>> Hi all,
>>>>>
>>>>> Could anyone help me how to check condition, and fill the data to the
>>>>> adjacent cell automatically?
>>>>>
>>>>> Such that, there are several columns at the worksheet.
>>>>>
>>>>> And I specified to use 2 columns (C and D) only.
>>>>>
>>>>> Column D contains characters in each cell.
>>>>> Column C is blank Column without data in all cell.
>>>>>
>>>>> It checks the number of the characters in each cell of column D.
>>>>> If the number of characters is 10 in D2, then fill "5" into C2
>>>>> If the number of characters is 20 in D3, then fill "4" into C3
>>>>>
>>>>> How can I implement that operation?
>>>>>
>>>>> Thanks for your in advance.
>>>>>
>>>>> TLee
>>>>>
>>>>>
>>>>>
>>>>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Making a MsgBox return cell data when search finds different data in an adjacent cell Don Guillett Microsoft Excel Discussion 0 4th Jul 2009 01:37 PM
How to Automatically Move Cell datato adjacent cell.. cardingtr Microsoft Excel Misc 1 17th Oct 2005 03:59 AM
Loop through for condition and input in adjacent cell bundyloco Microsoft Excel Programming 1 13th Jul 2005 09:35 AM
automatically fill in a cell if the adjacent cell has any value =?Utf-8?B?R2VvZ3JhcGhlcg==?= Microsoft Excel Programming 4 1st Jun 2005 03:40 PM
automatically insert date in adjacent cell? =?Utf-8?B?TWlrZSBCLg==?= Microsoft Excel Worksheet Functions 1 2nd Dec 2003 07:05 PM


Features
 

Advertising
 

Newsgroups
 


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