VBA Runtime 1004 error - How to change sheets?

DataBlake

Well-known Member
Joined
Jan 26, 2015
Messages
781
Office Version
  1. 2016
Platform
  1. Windows
Hello all,
I'm having a problem where i try to run a column moving macro using
Code:
    Worksheets("MHT").Activate

 Dim lastRow As Long
 lastRow = Range("A" & Rows.Count).End(xlUp).Row


    Columns("F:F").Select
    Selection.Cut
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight

the issue is that im running the macro from another sheet
if i remove the worksheet activate or select the code works perfectly
how can i start this macro from any other sheet and it go to the one i want it to and perform the column moving?

any help is greatly appreciated.
 
What happens if you close xl with the MHT empty, then re-open xl, paste the data & run the code?
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
What happens if you close xl with the MHT empty, then re-open xl, paste the data & run the code?

it gives the runtime error code.
note: when the runtime error code happens i have to use task manager to end excel. It will not allow me to click inside cells, close the program, or anything. Also looks like column A & B are meshed together. I can send you the workbook if you'd like.
 
Upvote 0
I can send you the workbook if you'd like.
Ok, but you will need to upload to a share site such as OneDrive, GoogleDrive, Dropbox, mark for sharing & post the link to the thread.
 
Upvote 0
Ok, but you will need to upload to a share site such as OneDrive, GoogleDrive, Dropbox, mark for sharing & post the link to the thread.

thank you so much.
so use whatever you want in MHT as the "data"
try once just running the macro by double clicking "Program Start"s MHT box
then remove whats in MHT, save, close, reopen and try to copy paste that same "data" in and then run the macro.

https://drive.google.com/file/d/1ZRGR0ek4rGyl37GAiXcPzqAAxq_oyJn8/view?usp=sharing
 
Last edited:
Upvote 0
It works ok for me.
Do you run the "Wheelpros" before "MHT"?
 
Upvote 0
It works ok for me.
Do you run the "Wheelpros" before "MHT"?

no each sheet is individually run.
weirdly enough i found out its the way i'm pasting the "data"
if you paste it as an entire sheet with the top left corner, and you go straight to Program Start, does it mess it up?
if i paste it from the rows it works
 
Upvote 0
apologies for not noticing this sooner but:
if i copy the data like this and paste into MHT
fHNNCLJ.png


I get this:
7VgoCvS.png
 
Upvote 0
Where are you copying the data from?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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