Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
MMH MMH is offline
external usenet poster
 
Posts: 14
Default Populating fields based on previous column values

Hello

I am trying to populate the cells in a column (column F) based on
information in columns B, C and D. Unfortunately I do not know how to code
this.

For example, I want to say that for all the rows where column C equals "AC",
column F should say "Agent's Charges". Then for all the rows where column D
has "OF", column F should say "Official Fees". And so on.

Could someone please tell me how I would write this in VBA. Thank you in
advance.

MMH
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default Populating fields based on previous column values

You may use the IF-THEN-ELSE conditional statements. Below is a simple example.

To test using the macro, populate some cells in column C and D with the
words you specified. Then select the adjacent cells in column F. Then run the
macro.

Sub checking()
Dim cell As Object
For Each cell In Selection.Cells
If cell.Offset(0, -3).Value = "AC" Then
cell.Value = "Agent's Charges"
ElseIf cell.Offset(0, -2).Value = "OF" Then
cell.Value = "Official Fees"
ElseIf cell.Offset(0, -4).Value = "XXXX" Then
'do something else
End If
Next
End Sub


Basically, for example, for a cell F1, the "cell.offset(0,-2).value" is
referring to the value of the cell in D1, i.e. 2 cells to the left.

Feel free to ask if you need further assistance. :

Regards,
Edwin Tam

http://www.vonixx.com



"MMH" wrote:

Hello

I am trying to populate the cells in a column (column F) based on
information in columns B, C and D. Unfortunately I do not know how to code
this.

For example, I want to say that for all the rows where column C equals "AC",
column F should say "Agent's Charges". Then for all the rows where column D
has "OF", column F should say "Official Fees". And so on.

Could someone please tell me how I would write this in VBA. Thank you in
advance.

MMH

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Populating fields based on previous column values

why don't you just use a VLOOKUP function?

"MMH" wrote:

Hello

I am trying to populate the cells in a column (column F) based on
information in columns B, C and D. Unfortunately I do not know how to code
this.

For example, I want to say that for all the rows where column C equals "AC",
column F should say "Agent's Charges". Then for all the rows where column D
has "OF", column F should say "Official Fees". And so on.

Could someone please tell me how I would write this in VBA. Thank you in
advance.

MMH

  #4   Report Post  
Posted to microsoft.public.excel.programming
MMH MMH is offline
external usenet poster
 
Posts: 14
Default Populating fields based on previous column values

Thanks Edwin - that does exactly what I wanted it to.

MMH

"Edwin Tam" wrote:

You may use the IF-THEN-ELSE conditional statements. Below is a simple example.

To test using the macro, populate some cells in column C and D with the
words you specified. Then select the adjacent cells in column F. Then run the
macro.

Sub checking()
Dim cell As Object
For Each cell In Selection.Cells
If cell.Offset(0, -3).Value = "AC" Then
cell.Value = "Agent's Charges"
ElseIf cell.Offset(0, -2).Value = "OF" Then
cell.Value = "Official Fees"
ElseIf cell.Offset(0, -4).Value = "XXXX" Then
'do something else
End If
Next
End Sub


Basically, for example, for a cell F1, the "cell.offset(0,-2).value" is
referring to the value of the cell in D1, i.e. 2 cells to the left.

Feel free to ask if you need further assistance. :

Regards,
Edwin Tam

http://www.vonixx.com

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
Based on data in previous column - sum of values in next column Beena K Excel Worksheet Functions 1 April 7th 09 07:23 PM
Populating a cell based on a range of values (Part III) akkrug New Users to Excel 3 June 26th 08 08:28 PM
Populating a Cell based on a Range of Values (Part II) akkrug New Users to Excel 6 June 22nd 08 02:40 PM
Populating a cell based on a range of values akkrug New Users to Excel 2 June 20th 08 03:09 PM
Populating a field based on lookup values Sav_C Excel Worksheet Functions 5 August 6th 06 02:49 AM


All times are GMT +1. The time now is 11:59 AM.

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"