How to create generic Macro (all variables)

marcn

New Member
Joined
Feb 13, 2020
Messages
15
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I need a generic macro that can take in three inputs: Yr grey (from droplist choice of 3 or more), Line items rows purple box (droplist- eg. Sales, Costs, Units) and Percentage - yellow box which contains the percentage to increase or decrease the line items the results replace the row.

I am attaching picture and code to date:

Here is code I wrote by kludging other codes together... yes, it is probably pathetic but I am not a VBA programmer and have no time to really learn at this time.

VBA Code:
Sub Consult_Monthly_ALL_Yr1()

'declare variables

    Application.Goto Reference:="TCS_ALL_YR1"
Dim ws As Worksheet
Dim rng As Range
Dim myVal As Range
Dim J11 As Integer
Set ws = Worksheets("3a-SalesForecastYear1")
Set rng = ws.Range("tcs_all_yr1")
For Each myVal In rng
If J11 < 100 Then
myVal = myVal.Value * ws.Range("H13")/12
ElseIf J11 > 100 Then
myVal = myVal.Value * ws.Range("H13") + myVal.Value/12
End If
Next myVal
End Sub

Note, the above select a array to multiply 3 rows at once, others use defined name to select single line item (row)

I was thinking of useing input box or userform where I ask for which year, which line items, and percent and that is fed to a generic macro. I know drplist choice can be done in userform... Im open to any idea or solution that reduces the number of separate macros.

thanks
Marc
 

Attachments

  • samplews.png
    samplews.png
    43 KB · Views: 17

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
sounds like a userform is doable for what you want to do, but you are excluding necessary info like what is in the dropdown, or where on in the workbook the data for said drop down is located.
feel free to be hyper specific as I am not in your profession and do not know what anything on your workbook actually means.
just take us from step 1 to step z in as much detail as you want to give. I'm not the smartest guy in the room so throwing a bunch of numbers and math at me is quite scary.

to fill in the gaps that you may be unaware of VBA can determine things dynamically such as:
the last row of a sheet/range
the last column of a sheet/range
etc

also posting your data using XL2BB would be more beneficial than using a screenshot as its gives us all the information of your sheet that you paste including ranges, formulas, etc
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top