Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-26-2018, 04:08 AM
rsrasc rsrasc is offline Need Help with Current Macro Windows 10 Need Help with Current Macro Office 2013
Competent Performer
Need Help with Current Macro
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default 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
Now, due to some unexpected changes, I would like to know if the above macro can be modified.

For example the below code will not changed
Code:
For Each ws In Worksheets(Array("130R", "135R", "140R"))
The same as



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
Reply With Quote
  #2  
Old 10-26-2018, 07:29 PM
Logit Logit is offline Need Help with Current Macro Windows 10 Need Help with Current Macro Office 2007
Expert
 
Join Date: Jan 2017
Posts: 533
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

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
Reply With Quote
  #3  
Old 10-27-2018, 06:02 AM
rsrasc rsrasc is offline Need Help with Current Macro Windows 10 Need Help with Current Macro Office 2013
Competent Performer
Need Help with Current Macro
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

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
Since I realized that some of the numbers in the range E4:P45 cannot be converted to negative numbers, my question was if the original macro given to me can be modified.
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"))
Now, under these three (3) sheets, "130R", "135", and "140R", in Column B, I have the following information or accounts with their corresponding values from Column E to Column P:

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
Reply With Quote
  #4  
Old 10-27-2018, 09:10 AM
Logit Logit is offline Need Help with Current Macro Windows 10 Need Help with Current Macro Office 2007
Expert
 
Join Date: Jan 2017
Posts: 533
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

.
It would be best to post a sample workbook. Leave out any confidential information.
Reply With Quote
  #5  
Old 10-27-2018, 10:12 AM
rsrasc rsrasc is offline Need Help with Current Macro Windows 10 Need Help with Current Macro Office 2013
Competent Performer
Need Help with Current Macro
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

Please find attached sample.

.
Attached Files
File Type: xlsm FY 19-SSE Budget File-TEST.xlsm (36.8 KB, 7 views)
Reply With Quote
  #6  
Old 10-27-2018, 10:19 AM
p45cal's Avatar
p45cal p45cal is offline Need Help with Current Macro Windows 10 Need Help with Current Macro Office 2016
Expert
 
Join Date: Apr 2014
Posts: 866
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

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
Reply With Quote
  #7  
Old 10-27-2018, 02:42 PM
rsrasc rsrasc is offline Need Help with Current Macro Windows 10 Need Help with Current Macro Office 2013
Competent Performer
Need Help with Current Macro
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

Hi pcal45,

Thank you for the code. Great job.

I'm really happy with the results.

Regards,
rsrasc
Reply With Quote
  #8  
Old 10-28-2018, 04:31 AM
p45cal's Avatar
p45cal p45cal is offline Need Help with Current Macro Windows 10 Need Help with Current Macro Office 2016
Expert
 
Join Date: Apr 2014
Posts: 866
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

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
Reply With Quote
  #9  
Old 10-28-2018, 05:41 AM
rsrasc rsrasc is offline Need Help with Current Macro Windows 10 Need Help with Current Macro Office 2013
Competent Performer
Need Help with Current Macro
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

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
Since I was playing with the macro, I also realized I can change from negative to positive by inverting the greater (>) than sign to less than sign (<).

You guys are amazing.

Thank you for your support.

Much appreciated

Regards,
rsrasc
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help with Current Macro Macro to auto-save pdf using text on page + current date hysterical.useless Word VBA 12 02-05-2018 02:17 PM
Need Help with Current Macro 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
Need Help with Current Macro Macro for moving one cell down from current position Johnny thunder Word VBA 3 04-07-2011 04:44 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:28 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft