#1
|
|||
|
|||
Need Help with Current Macro
Hi all,
The following macro was given to me in a previous post and it is working great. Code:
Sub test() Dim Cell As Range Dim ws As Worksheet For Each ws In Worksheets(Array("130R", "135R", "140R")) For Each Cell In ws.Range("E4:P45") If Cell.Value > 0 Then Cell.Value = Cell.Value * -1 End If Next Cell Next ws End Sub For example the below code will not changed Code:
For Each ws In Worksheets(Array("130R", "135R", "140R")) Code:
For Each Cell In ws.Range("E4:P45") If Cell.Value > 0 Then Cell.Value = Cell.Value * -1 In my file in column B, from row 4 to 43, I have different account numbers. For example, some of the accounts listed in Column B are the following: Circulation-All Other Single-Gross Sales Circulation-All Other Single-Gross Sales (Sun) Other Printing Revenue Other Printing Services-Quick Print Therefore, since only these accounts needs to be converted to negative, I was wondering how this can be accomplished. As always, thank you in advance for your assistance and cooperation. Cheers! rsrasc |
#2
|
|||
|
|||
Code:
Sub test() Dim Cell As Range Dim ws As Worksheet For Each ws In Worksheets(Array("130R", "135R", "140R")) For Each Cell In ws.Range("E4:P45") If Cell.Value > 0 Then Cell.Value = Cell.Value * -1 End If Next Cell For Each Cell In ws.Range("B4:B43") If Cell.Value > 0 Then Cell.Value = Cell.Value * -1 End If Next Cell Next ws End Sub |
#3
|
|||
|
|||
Thank you Logit for your reply but it did not work.
Let me see if can get a better explanation. The code given to me in the below code will convert all numbers from positive to negative for any number in the range E4 through P45. Code:
Sub test() Dim Cell As Range Dim ws As Worksheet For Each ws In Worksheets(Array("130R", "135R", "140R")) For Each Cell In ws.Range("E4:P45") If Cell.Value > 0 Then Cell.Value = Cell.Value * -1 End If Next Cell Next ws End Sub This is now where a new macro or a modified macro is needed. New requirement: The modified macro will still need the following code: Code:
For Each ws In Worksheets(Array("130R", "135R", "140R")) Local Advertising-Full Run General Advertising-Full Run Advertising-Insert-Local-Full Run Advertising-Classified-Display Advertising-Classified-Liners Advertising-Special Supplements Circulation-AAFES/NEX-Gross Sales Circulation-AAFES/NEX-Returns Circulation-AAFES/NEX-Gross Sales (Sun) Circulation-AAFES/NEX-Returns(Sun) Circulation-DECA-Gross Sales(M-Sat) Circulation-DECA-Returns(M-Sat) Circulation-DECA-Gross Sales(Sun) Circulation-DECA-Returns (Sun) Circulation-Home Delivery-Gross Sales Circulation-Home Delivery-Gross Sales (Sun) Circulation-All Other Single-Gross Sales Circulation-All Other Single-Returns Circulation-All Other Single-Gross Sales (Sun) Circulation-All Other Single-Returns (Sun) Circulation-Vending Machines-Gross Sales Foreign Currency Conversion Gains Circulation-Vending Machines-Pilferage Circulation-Vending Machines-Gross Sales (Sun) Circulation-Vending Machines-Returns (Sun) Circulation-Vending Machines-Pilferage (Sun) Circulation-Exercises/Maneuvers-Gross Sales Circulation-Exercises/Maneuvers-Gross Sales (Sun) Circulation-Mail Subscriptions-Gross Sales Circulation-Mail Subscriptions-Gross Sales (Sun) Circulation-Direct Drops-Gross Sales Circulation-Direct Drops-Gross Sales (Sun) Circulation-Bulk Sales-(Daily) Circulation-Bulk Sales-(Sunday) Other Printing Revenue Other Printing Services-Quick Print Foreign Currency Conversion Gains Other Publications Sales-Other Publ Delivery Advertising-Internet Revenue Other Revenue Out of the above listing or information in Column B, I would like the macro to only convert the following accounts from positive to negative numbers. Circulation-AAFES/NEX-Returns Circulation-AAFES/NEX-Returns(Sun) Circulation-DECA-Returns(M-Sat) Circulation-DECA-Returns (Sun) Circulation-All Other Single-Returns Circulation-All Other Single-Returns (Sun) Circulation-Vending Machines-Pilferage Circulation-Vending Machines-Returns (Sun) Circulation-Vending Machines-Pilferage (Sun) Therefore, since these are the only accounts that needs to be converted from positive numbers to negative numbers, then my question is if this is possible. I hope this clarify what is needed. Thank you all for your assistance and cooperation. Regards, rsrasc |
#4
|
|||
|
|||
.
It would be best to post a sample workbook. Leave out any confidential information. |
#5
|
|||
|
|||
Please find attached sample.
. |
#6
|
||||
|
||||
untested:
Code:
Sub test() Dim Cell As Range Dim ws As Worksheet AcctsToMakeNegative = Array("Circulation-AAFES/NEX-Returns", "Circulation-AAFES/NEX-Returns(Sun)", "Circulation-DECA-Returns(M-Sat)", "Circulation-DECA-Returns (Sun)", "Circulation-All Other Single-Returns", "Circulation-All Other Single-Returns (Sun)", "Circulation-Vending Machines-Pilferage", "Circulation-Vending Machines-Returns (Sun)", "Circulation-Vending Machines-Pilferage (Sun)") For Each ws In Worksheets(Array("130R", "135R", "140R")) For Each cll In ws.Range("B4:B45").Cells If Not IsError(Application.Match(cll.Value, AcctsToMakeNegative, 0)) Then For Each Cell In cll.Offset(, 3).Resize(, 12).Cells If Cell.Value > 0 Then Cell.Value = Cell.Value * -1 Next Cell End If Next cll Next ws End Sub |
#7
|
|||
|
|||
Hi pcal45,
Thank you for the code. Great job. I'm really happy with the results. Regards, rsrasc |
#8
|
||||
|
||||
I note that every account name you want to make negative contains either the word Return or Pilferage, so instead of having a list of full account names (which have to be exactly the same as on your sheet) you could look for instances of (say) return and/or pilfer in the account names instead.
In the code below, there's a line: myWords = Array("returns", "pilfer") to which you can add other words to find in account names you want to make negative. Code:
Sub test() Dim Cell As Range, ws As Worksheet, myWords, cll As Range myWords = Array("returns", "pilfer") For Each ws In Worksheets(Array("130R", "135R", "140R")) For Each cll In ws.Range("B4:B45").Cells If UBound(Filter(Application.IsErr(Application.Search(myWords, cll.Value)), "True", False)) > -1 Then For Each Cell In cll.Offset(, 3).Resize(, 12).Cells If Cell.Value > 0 Then Cell.Value = Cell.Value * -1 Next Cell End If Next cll Next ws End Sub |
#9
|
|||
|
|||
Hi p45cal,
Your observation is well taken. I'm sure your macro will help me somehow in the future. Code:
If Cell.Value > 0 Then Cell.Value = Cell.Value * -1 You guys are amazing. Thank you for your support. Much appreciated Regards, rsrasc |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to auto-save pdf using text on page + current date | hysterical.useless | Word VBA | 12 | 02-05-2018 02:17 PM |
macro, data import from the ONLY text file in current folder | ue418 | Excel Programming | 5 | 10-28-2017 12:52 PM |
a macro that can copy data from copy.xls to our current excel macro.xls based on criteria: | udhaya | Excel Programming | 1 | 11-12-2015 10:12 AM |
A macro that moves the current paragraph up or down? | New Daddy | Word VBA | 2 | 04-13-2014 02:25 PM |
Macro for moving one cell down from current position | Johnny thunder | Word VBA | 3 | 04-07-2011 04:44 PM |