i have a dummy workbook where i test all macros to make sure it works as intended. macro below works but
when i open a new workbook which has the actual data i want to manipulate, the macro only makes changes in the dummy workbook even though the real one i opened up has the same tab name...basically i want the macro to affect the current workbook im in but it wont work even if both workbooks have the same worksheet name. i do not want to cut and paste, what should be changed for this to work, thanks
[/ Sub TVS()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
' Change "Not on a Category" to the name of your worksheet
Set ws = ThisWorkbook.Sheets("Not on a Category")
' Find the last row with data in column N
lastRow = ws.Cells(ws.Rows.Count, "N").End(xlUp).Row
' Loop through each row
For i = 2 To lastRow ' Assuming row 1 is headers
' Check conditions and update column H accordingly
If ws.Cells(i, "N").Value = "TELEVISIONS-Televisions" Then
If ws.Cells(i, "W").Value = "Open Box" Then
ws.Cells(i, "H").Value = "tradeport"
ElseIf ws.Cells(i, "W").Value = "Defective / unspecified" Then
If ws.Cells(i, "F").Value = "Samsung" Then
ws.Cells(i, "H").Value = "tradeport"
Else
ws.Cells(i, "H").Value = "pic needed"
End If
ElseIf ws.Cells(i, "W").Value = "Damaged" Then
If ws.Cells(i, "F").Value = "LG" Then
ws.Cells(i, "H").Value = "pic needed"
Else
ws.Cells(i, "H").Value = "global"
End If
End If
End If
Next i
End Sub /]
when i open a new workbook which has the actual data i want to manipulate, the macro only makes changes in the dummy workbook even though the real one i opened up has the same tab name...basically i want the macro to affect the current workbook im in but it wont work even if both workbooks have the same worksheet name. i do not want to cut and paste, what should be changed for this to work, thanks
[/ Sub TVS()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
' Change "Not on a Category" to the name of your worksheet
Set ws = ThisWorkbook.Sheets("Not on a Category")
' Find the last row with data in column N
lastRow = ws.Cells(ws.Rows.Count, "N").End(xlUp).Row
' Loop through each row
For i = 2 To lastRow ' Assuming row 1 is headers
' Check conditions and update column H accordingly
If ws.Cells(i, "N").Value = "TELEVISIONS-Televisions" Then
If ws.Cells(i, "W").Value = "Open Box" Then
ws.Cells(i, "H").Value = "tradeport"
ElseIf ws.Cells(i, "W").Value = "Defective / unspecified" Then
If ws.Cells(i, "F").Value = "Samsung" Then
ws.Cells(i, "H").Value = "tradeport"
Else
ws.Cells(i, "H").Value = "pic needed"
End If
ElseIf ws.Cells(i, "W").Value = "Damaged" Then
If ws.Cells(i, "F").Value = "LG" Then
ws.Cells(i, "H").Value = "pic needed"
Else
ws.Cells(i, "H").Value = "global"
End If
End If
End If
Next i
End Sub /]