macro error even if both worksheets are correctly named

Tonyk1051

Board Regular
Joined
Feb 1, 2021
Messages
132
Office Version
  1. 2019
Platform
  1. Windows
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 /]
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
The code needs to be either in the new workbook or your PERSONAL workbook
 
Upvote 0
Solution

Forum statistics

Threads
1,215,212
Messages
6,123,654
Members
449,113
Latest member
Hochanz

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