VBA solution for selecting a range of months

joetejas

New Member
Joined
Feb 5, 2019
Messages
17
The purpose is to select a month from data validation, and other cells populate future months. Then when selecting a different month those same cells change.

Is there a way to capture multi months in different cells when a case is selected?
Selecting Jan, D2=Feb,D3=Mar,D4=Apr
Selecting Feb D2= Mar ,D3= Apr, D4=May

I have this so far...

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("C2")) Is Nothing Then
Select Case Range("C2")
Case "Jan": Range("D2").Value = "Feb"
Case "Feb": Range("L2").Value = "Mar"
Case "Mar": Range("M2").Value = "Apr"
Case "Apr": Range("N2").Value = "May"
Case "May": Range("O2").Value = "Jun"
Case "Jun": Range("P2").Value = "Jul"
Case "Jul": Range("Q2").Value = "Aug"
Case "Aug": Range("R2").Value = "Sep"
Case "Sep": Range("S2").Value = "Nov"
Case "Oct": Range("T2").Value = "Dec"
Case "Nov": Range("U2").Value = 10
Case "Dec": Range("V2").Value = 11
End Select
End If


End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
You can do it like
Code:
      Case "Jan"
         Range("D2").Value = "Feb"
         Range("D3").Value = "Mar"
         Range("D4").Value = "Apr"
      Case "Feb"
 
Upvote 0
Oh yes this works. My next question how can the previous month be deselected when Case "Feb" is active.


I want all future months highlighted and all previous be deselected.




Case "Feb": Range("P1").Value = "Feb"
Range("O1").Value = "Feb"
Range("P1").Value = "Mar"
Range("Q1").Value = "Apr"
 
Upvote 0
What do you mean "deselecting" previous months?
 
Upvote 0
I selected Feb first then Mar, but month Feb is static and was not removed. I only want future months, when selecting a month

Mar
Apr
May
JunJulAugSepOctNov

<tbody>
</tbody>
Feb
Mar
AprMayJunJulAugSepOctNovDec

<colgroup><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"></colgroup><tbody>
</tbody>

<colgroup><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"><col width="90"></colgroup><tbody>
</tbody>
 
Upvote 0
Glad you figured it out & thanks for the feedback
 
Upvote 0
Your welcome,
I do have one more question. Now I have a VBA setup I need a formula to keep value when a month is present or read zero if the month is not present.
-
Feb
Mar

<tbody>
</tbody>

$0($90,975)($104,599)

<tbody>
</tbody>

Current formal in the cell.
=IF($I4="Other - Explain in Comments",((AD4-$AC4)/$AC4)*P4,IF(AP4>0,((P4*AP4*((AD4-$BB4)/$BB4))+(((VLOOKUP($C4,'Market Input'!$G:$AL,BD$1,FALSE)-$BB4)/$BB4)*P4*(1-AP4))),((VLOOKUP($C4,'Market Input'!$G:$AL,BD$1,FALSE)-$BB4)/$BB4)*P4))
 
Last edited:
Upvote 0
Maybe add another if to your formula
=IF(xx="",0,IF($I4="Other - Explain in Comments",
where xx is the cell with the month
 
Upvote 0
Great, I used the following and it zeroed out! I made another row above my columns and if there is no month present the cell will equal 0.

=IF($BD$3<>0,IF($I4="Other - Explain in Comments",
,0)






Maybe add another if to your formula
=IF(xx="",0,IF($I4="Other - Explain in Comments",
where xx is the cell with the month
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,947
Members
449,095
Latest member
nmaske

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