randonneur
New member
- Joined
- Aug 9, 2011
- Messages
- 5
- Reaction score
- 0
- Points
- 0
I’m using the following code in a User Form to copy values to set a cell range based on the location. I would like to adjust the code to copy the value to different cells based on the date listed in my date box and the location selected from my combo box.
Ex: If the region Texas was chosen from my combo list and the date said 9/15/11 in the date box, it would copy the value from F120 to B131
If the region Texas was chosen from my combo list and the date said 10/1/11 in the date box, it would copy the value from F120 to B132.
This process would repeat all the way down to row B148. The dates used are the 1st and 15th of each month through May 2012.
I would also need the code to follow the same example above for the other locations listed. The only difference is the cell range.
Ex: Connecticut would be my next range and would need to copy from F121 to E131 thru E148.
Once I have an understanding of how the code is written for two dates and their locations , I can go back and duplicate the code for the remaining locations.
Thanks
Allen
Ex: If the region Texas was chosen from my combo list and the date said 9/15/11 in the date box, it would copy the value from F120 to B131
If the region Texas was chosen from my combo list and the date said 10/1/11 in the date box, it would copy the value from F120 to B132.
This process would repeat all the way down to row B148. The dates used are the 1st and 15th of each month through May 2012.
I would also need the code to follow the same example above for the other locations listed. The only difference is the cell range.
Ex: Connecticut would be my next range and would need to copy from F121 to E131 thru E148.
Once I have an understanding of how the code is written for two dates and their locations , I can go back and duplicate the code for the remaining locations.
Code:
[SIZE=3][FONT=Calibri]Option Explicit[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]Private Sub cmdCopyValue_Click()[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] If cboLocation.ListIndex <> -1 Then[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Worksheets("Monthly Data").Range("F" & cboLocation.ListIndex + 120).Copy Worksheets("Monthly Data").Range("B" & cboLocation.ListIndex + 130)[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Worksheets("Monthly Data").Range("B" & cboLocation.ListIndex + 130).Value = Worksheets("Monthly Data").Range("B" & cboLocation.ListIndex + 130).Value[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] End If[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]End Sub[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]Private Sub DTPicker1_Click()[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] Me.TextBox1.Value = DTPicker1.Value[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]End Sub[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]Private Sub UserForm_Click()[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]End Sub[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]Private Sub UserForm_Initialize()[/FONT][/SIZE]
[SIZE=3][FONT=Calibri] cboLocation.List = Worksheets("Monthly Data").Range("A2:A8").Value[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]End Sub[/FONT][/SIZE]
Thanks
Allen