I am new to using VBA in Excel. Just want to get that out in the open. What I am trying to do is create an inventory list for multiple products. Basically, I will have one sheet in my workbook per device type. I will have 4 columns. 1= Serial Number / 2= MAC Address / 3= Device Type / 4= Distributed? (column 4 has a drop down list of yes or no). I want to be able to go to my list on Sheet1 and select 'yes' in the drop down list of column 4. Then, that row automatically gets moved out of Sheet1 and onto Sheet2 (A distributed list of devices). I then have some basic formulas that keep count of the device list on Sheet1 (this is not the issue).
I was able to find some code on another forum that has this functionality working great from Sheet1 to Sheet2. No issues at all, and it does exactly what I want it to do. The way I did this was Module1 set up with the code with sheet names in the code and a Sheet1 code that was also posted along wih the orignal code. See below:
Module1:
Sheet1:
However, I have other device types on other Sheets that I would like to do the same exact thing in the same workbook. I would have the same exact set up as sheet1 and sheet2 for the data side, but I would want to be able to do this same functionality but from Sheet3 (a diff device inventory list) to Sheet4 (the distributed device list for that type).
I tried creating another Module and repeating the code with the sheet names replaced with the new ones as well as Sheet2 code just copied over and I get an Ambiguous error.
Can anyone assist a novice with this?
I was able to find some code on another forum that has this functionality working great from Sheet1 to Sheet2. No issues at all, and it does exactly what I want it to do. The way I did this was Module1 set up with the code with sheet names in the code and a Sheet1 code that was also posted along wih the orignal code. See below:
Module1:
VBA Code:
Sub MoveBasedOnValue()
Dim xRg As Range
Dim xCell As Range
Dim A As Long
Dim B As Long
Dim C As Long
A = Worksheets("XBs Avail").UsedRange.Rows.Count
B = Worksheets("XBs Distributed").UsedRange.Rows.Count
If B = 1 Then
If Application.WorksheetFunction.CountA(Worksheets("XBs Distributed").UsedRange) = 0 Then B = 0
End If
Set xRg = Worksheets("XBs Avail").Range("D1:D" & A)
On Error Resume Next
Application.ScreenUpdating = False
For C = 1 To xRg.Count
If CStr(xRg(C).Value) = "yes" Then
xRg(C).EntireRow.Copy Destination:=Worksheets("XBs Distributed").Range("A" & B + 1)
xRg(C).EntireRow.Delete
If CStr(xRg(C).Value) = "yes" Then
C = C - 1
End If
B = B + 1
End If
Next
Application.ScreenUpdating = True
End Sub
Sheet1:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Z As Long
Dim xVal As String
On Error Resume Next
If Intersect(Target, Range("D:D")) Is Nothing Then Exit Sub
Application.EnableEvents = False
For Z = 1 To Target.Count
If Target(Z).Value > 0 Then
Call MoveBasedOnValue
End If
Next
Application.EnableEvents = True
End Sub
However, I have other device types on other Sheets that I would like to do the same exact thing in the same workbook. I would have the same exact set up as sheet1 and sheet2 for the data side, but I would want to be able to do this same functionality but from Sheet3 (a diff device inventory list) to Sheet4 (the distributed device list for that type).
I tried creating another Module and repeating the code with the sheet names replaced with the new ones as well as Sheet2 code just copied over and I get an Ambiguous error.
Can anyone assist a novice with this?