Adjusting UserForm VBA

ultracyclist

Active Member
Joined
Oct 6, 2010
Messages
274
Office Version
  1. 365
Platform
  1. Windows
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.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>Example: 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.<o:p></o:p>
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.<o:p></o:p>
This process would repeat all the way down to row B148. The dates used are the 1<SUP>st</SUP> and 15<SUP>th</SUP> of each month through May 2012.
<o:p></o:p>
I would also need the code to follow the same example above for the other locations listed. The only difference is the cell range.
<o:p></o:p>
Example: Connecticut would be my next range and would need to copy from F121 to E131 thru E148.
<o:p></o:p>
Once I have an understanding of how the first two are created, 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]
[SIZE=3][FONT=Calibri]<o:p>[/FONT][/SIZE]
</o:p>
<o:p></o:p>
I'm using a macro button inside my Userform to perform the copy function.

Any thoughts would be greatly appreciated.

Thanks,

Allen
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,224,551
Messages
6,179,473
Members
452,915
Latest member
hannnahheileen

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