Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Help Needed - VBA If statement!

Hello fellow Excel Users,

I am new to VBA in Excel and need some assistance.

Background: I have a workbook "Corporate Sales" which contains (13)
worksheets, one for each month of the year (Corprate Sales Jan 2004 -
Corprate Sales Dec 2004), and one worksheet that I want to use as a
settings worksheet (Settings Worksheet). I have tried to automate each
worksheet to populate the sales territory based on the salesman's
initials using the following formula:

-----------------------------
column "B" = Sales Territory (contains the formula)
column "C" = Salesman's Initial

=IF(OR(C7="AM",C7="BP",C7="DA",C7="JS",C7="SW",C7= "WB"),"No.",IF(OR(C7="JD",C7="KO",C7="PD",C7="SP") ,"So.","
"))
-----------------------------

unfortunately, if a salesman is added or deleted I need to manually
modify each of the (12) worksheets. I want to develope a VBA "IF"
statement which will do the following:

-----------------------------
Compare salesman's inital columns:

"Settings Worksheet - C (salesman's initials)"

to

"Corprate Sales Jan 2004 - C (salesman's initials)"

and if

"Settings Worksheet - D (sales territory)" = North or South

populate

"Corprate Sales Jan 2004 - D (sales territory)" with No. or So.
-----------------------------

I have tried the following, however, being new to VBA I could not get
anything to work:

-----------------------------
Function GetSalesTerritory(strRep As String, varVal As Variant) As
Variant

If strRep = Worksheet("Settings Worksheet").Cell("C2") And
Worksheet("Settings Worksheet").Cell("D2").Value = "North" Then
Worksheet("Corprate Sales Jan 2004").Cell("B2").Value = "No."
End If

End Function
-----------------------------

I put "=GetSalesTerritory()" in "Corprate Sales Jan 2004 - C (salesmans
initals)" to call the function, but nothing seems to work.

Any and all assiatance would be greatly appreciated.

Also if anyone knows of a good VBA book for Beginners / Intermediate
that I could use as a reference would be helpful.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Help Needed - VBA If statement!

Create a separate table of Salespeople/Regions and use VLookup. Then,
something like the following (assuming your table is in a Named Range called
SalespeopleRegions with Initials in column 1 and Region in column 2) would
return the proper region:

=VLookup(C7,SalespeopleRegions,2)

When salespeople are added, you only need to add them to the table, no need
to touch the formula.

--
George Nicholson

Remove 'Junk' from return address.


wrote in message
oups.com...
Hello fellow Excel Users,

I am new to VBA in Excel and need some assistance.

Background: I have a workbook "Corporate Sales" which contains (13)
worksheets, one for each month of the year (Corprate Sales Jan 2004 -
Corprate Sales Dec 2004), and one worksheet that I want to use as a
settings worksheet (Settings Worksheet). I have tried to automate each
worksheet to populate the sales territory based on the salesman's
initials using the following formula:

-----------------------------
column "B" = Sales Territory (contains the formula)
column "C" = Salesman's Initial

=IF(OR(C7="AM",C7="BP",C7="DA",C7="JS",C7="SW",C7= "WB"),"No.",IF(OR(C7="JD",C7="KO",C7="PD",C7="SP") ,"So.","
"))
-----------------------------

unfortunately, if a salesman is added or deleted I need to manually
modify each of the (12) worksheets. I want to develope a VBA "IF"
statement which will do the following:

-----------------------------
Compare salesman's inital columns:

"Settings Worksheet - C (salesman's initials)"

to

"Corprate Sales Jan 2004 - C (salesman's initials)"

and if

"Settings Worksheet - D (sales territory)" = North or South

populate

"Corprate Sales Jan 2004 - D (sales territory)" with No. or So.
-----------------------------

I have tried the following, however, being new to VBA I could not get
anything to work:

-----------------------------
Function GetSalesTerritory(strRep As String, varVal As Variant) As
Variant

If strRep = Worksheet("Settings Worksheet").Cell("C2") And
Worksheet("Settings Worksheet").Cell("D2").Value = "North" Then
Worksheet("Corprate Sales Jan 2004").Cell("B2").Value = "No."
End If

End Function
-----------------------------

I put "=GetSalesTerritory()" in "Corprate Sales Jan 2004 - C (salesmans
initals)" to call the function, but nothing seems to work.

Any and all assiatance would be greatly appreciated.

Also if anyone knows of a good VBA book for Beginners / Intermediate
that I could use as a reference would be helpful.



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
IF statement help needed Bruce D. Excel Discussion (Misc queries) 3 May 5th 10 03:26 AM
If statement help needed ah Excel Worksheet Functions 16 June 19th 07 09:19 PM
If statement ... help needed. parsonsamie Excel Worksheet Functions 3 December 14th 06 12:43 AM
Help with IF statement needed Paul B. Excel Worksheet Functions 5 August 28th 06 05:19 PM
If Statement help needed please Ian Harris Excel Worksheet Functions 3 December 3rd 04 02:04 PM


All times are GMT +1. The time now is 08:26 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"