Need code to work when I am on any sheet

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
I can't understand why this code only works for the 1st 16 rows if I am NOT on the sheet, yet works fully when I am on the sheet. I need it to work off a command button that is on a userform and I can be on any sheet.

VBA Code:
      Dim wb As Workbook: Set wb = ThisWorkbook
            Dim ws As Worksheet
            Set ws = wb.Sheets("PasteSheet")
        
            ws.Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row).Formula = "=TRIM(MID(SUBSTITUTE(A2,""."",REPT("" "",999)),999,999))"
            ws.Range("C2:C" & Range("B" & Rows.Count).End(xlUp).Row).Formula = "=(""https://www.Yahoo.com/""&SUBSTITUTE(B2, "" "", """")&""/"")"
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
It will calculate the last row based on the active sheet, you need to qualify all ranges with the worksheet.
 
Upvote 0
Thanks Fluff

The range is Dynamic so how is it done. Date goes in 2PasteSheet" column A and then the code is run. It needs to work for the dynamic range
 
Upvote 0
Just put the ws. in front of all the ranges as you have done for the outer range.
 
Upvote 0
Solution
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,211
Members
448,554
Latest member
Gleisner2

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