I'm stuck!!!
Background
I have a user form. Once it loads it prompts the user to select a department. Depending on the selection that the user makes for the department, it needs to select a certain range. IE if they select grocery then the range is B6:G16. It then copies that data range and pastes to a different location..well that's what it is supposed to do!!!
My Issue is that I can't seem to get the ranges to work. I am new to vba and I don't quite understand what I am doing wrong...
My code is as shown below:
Background
I have a user form. Once it loads it prompts the user to select a department. Depending on the selection that the user makes for the department, it needs to select a certain range. IE if they select grocery then the range is B6:G16. It then copies that data range and pastes to a different location..well that's what it is supposed to do!!!
My Issue is that I can't seem to get the ranges to work. I am new to vba and I don't quite understand what I am doing wrong...
My code is as shown below:
Code:
Private Sub cmdOK_Click()
Dim WB As Workbook
Dim Dept As Variant
Dim Source As Variant
Dim RangeG As Range
Dim RangeP As Range
Dim RangeV As Range
Set RangeG = Range("B6:G16")
Set RangeP = Range("B18:G28")
Set RangeV = Range("B18:G28")
Set WB = Workbooks(Dir(ActiveWorkbook.FullName))
Debug.Print WB.FullName
WB.Activate
Sheets("Sales").Select
Range("j2").Select
Dept = Range("j2")
MsgBox "Your Dept is " & Dept & " Is this correct?", vbYesNo, "Department"
If vbYes = 6 Then
If cboDepartment = Dept Then
Select Case cboDepartment
Case "Grocery"
Source = RangeG
Case "Perishables"
Source = RangeP
Case "General Merchandise"
Source = RangeV
Workbooks.Open FileName:="C:\Testing\JR DW Data.xls"
Sheets("Sales").Select
'Range("B6:G16").Select
Source.Select
Selection.Copy
WB.Activate
Sheets("Sales").Select
Range("B24").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Windows("JR DW Data.xls").Activate
JunkData.SetText ""
JunkData.PutInClipboard
ActiveWorkbook.Close SaveChanges:=False
End If ' end if for making sure cbodepartment = dept
End If ' end if for if it is the wrong dept
End Sub