I have spent a ton of time trying to get this scenario to work. I have a main page in Excel which has a slew of command buttons we will call this sheet ("Home") and one of the buttons I just cannot get to work the way I need it to.
Scenario:
I click a command button which needs to copy data from another worksheet based on the user input that was being searched on and then copy that data to a third worksheet.
Here is the code I have now:
Private Sub CommandButtonSvr_Click()
Dim LastRow, i
Sheets ("UIS-Domain").Select
Sheets("UIS-Domain").Range ("A:IV")
LastRow = Range("C" & Rows.Count).End(xlUp).Row
Sheets("SheetTmp").Columns("A:IV").ClearContents
objectClass = InputBox("Please enter the objectClass:")
If objectClass = "" Then
Exit Sub
End If
For i = 1 To LastRow
If Cells(i, "C").Value = objectClass Then
Cells(i, "C").EntireRow.Copy Destination:= _
Sheets("SheetTmp").Range("A" & Rows.Count).End(xlUp). _
Offset(1, 0)
ctr = ctr + 1
End If
Next
If ctr = 0 Then
MsgBox "There was no match for " & objectClass, vbOKOnly, "Not Found"
Else
Sheets("SheetTmp").Columns("A:IV").AutoFit
Sheets("SheetTmp").Select
End If
End Sub
The line put in orange is the line not working I have tried so many different ways I just cannot get it to work. If I run this code without
Sheets ("UIS-Domain").Select
Sheets("UIS-Domain").Range ("A:IV")
on the worksheet where the data is instead of the worksheet ("Home") it works. Please advise.
Thank you
Scenario:
I click a command button which needs to copy data from another worksheet based on the user input that was being searched on and then copy that data to a third worksheet.
Here is the code I have now:
Private Sub CommandButtonSvr_Click()
Dim LastRow, i
Sheets ("UIS-Domain").Select
Sheets("UIS-Domain").Range ("A:IV")
LastRow = Range("C" & Rows.Count).End(xlUp).Row
Sheets("SheetTmp").Columns("A:IV").ClearContents
objectClass = InputBox("Please enter the objectClass:")
If objectClass = "" Then
Exit Sub
End If
For i = 1 To LastRow
If Cells(i, "C").Value = objectClass Then
Cells(i, "C").EntireRow.Copy Destination:= _
Sheets("SheetTmp").Range("A" & Rows.Count).End(xlUp). _
Offset(1, 0)
ctr = ctr + 1
End If
Next
If ctr = 0 Then
MsgBox "There was no match for " & objectClass, vbOKOnly, "Not Found"
Else
Sheets("SheetTmp").Columns("A:IV").AutoFit
Sheets("SheetTmp").Select
End If
End Sub
The line put in orange is the line not working I have tried so many different ways I just cannot get it to work. If I run this code without
Sheets ("UIS-Domain").Select
Sheets("UIS-Domain").Range ("A:IV")
on the worksheet where the data is instead of the worksheet ("Home") it works. Please advise.
Thank you
Last edited: