Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-22-2023, 09:03 PM
soroush.kalantari soroush.kalantari is offline The set range is unexpectedly changed. Windows 10 The set range is unexpectedly changed. Office 2016
Competent Performer
The set range is unexpectedly changed.
 
Join Date: Jun 2021
Posts: 115
soroush.kalantari is on a distinguished road
Default The set range is unexpectedly changed.


I have written a macro that in part of it, I set the selection (for example, range” AD4 to BC 11”) to” T1” and then make a copy of this selection and paste it in another range (for example, range” BD4 to CC 11”) and then set the new range to another variable. (for example,T4).
Now my problem is when I set T4, the T1 unexpectedly is no longer the old selection (range” AD1 to BC 11”) but has converted to the range I have assigned it to T4 (” BD4 to CC 11”.see the excel attachment. . The code is assigned to blue circle).
Can you guide me on this issue?
Attached Files
File Type: xlsm question.xlsm (89.3 KB, 2 views)
Reply With Quote
  #2  
Old 08-24-2023, 03:52 AM
p45cal's Avatar
p45cal p45cal is offline The set range is unexpectedly changed. Windows 10 The set range is unexpectedly changed. Office 2021
Expert
 
Join Date: Apr 2014
Posts: 871
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

By inserting cells with
Selection.Insert Shift:=xlToRight
you have moved your t1 range to the right. If those cells had values, they too would move to the right.
Maybe this will show you what goes on and what you can do. Step through the code with F8 on the keyboard:
Code:
Sub monthprocess()
Dim t1 As Range, tNew As Range

Set t1 = Selection
Selection.Insert Shift:=xlToRight
Set tNew = Selection 'because the newly inserted range is selected

t1.Select
tNew.Select
End Sub
Reply With Quote
  #3  
Old 08-25-2023, 12:11 AM
soroush.kalantari soroush.kalantari is offline The set range is unexpectedly changed. Windows 10 The set range is unexpectedly changed. Office 2016
Competent Performer
The set range is unexpectedly changed.
 
Join Date: Jun 2021
Posts: 115
soroush.kalantari is on a distinguished road
Default

Thank you. I got it.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy/paste into Excel Pro 2013 wraps a row unexpectedly mgl_8 Excel 1 04-30-2018 11:26 PM
The set range is unexpectedly changed. Formats in text boxes in Word 2016 changing unexpectedly PugwashAtNPEU Word 4 05-04-2017 05:53 AM
HELP! Excel background color changing unexpectedly Doug Needham Excel 0 12-08-2016 08:22 AM
Outlook 2010 unexpectedly closes herby325 Outlook 0 07-06-2016 08:44 AM
The set range is unexpectedly changed. Project closes unexpectedly preetsp Project 3 04-22-2014 06:50 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:16 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft