How to prevent deleting of cells messing funtion ranges

Zetori

New Member
Joined
Jul 6, 2011
Messages
42
Hiya

I have macro that brings information from outlook to excel. In the beginning of macro, it deletes range of cells. That destroys the functions that target those cells. Is there a way avoid that? Using some different method or ?

Code:
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim myCalItems As Outlook.Items
Dim ItemstoCheck As Outlook.Items
Dim ThisAppt As Outlook.AppointmentItem
Dim MyItem As Object
Dim StringToCheck As String
Set Mybook = Excel.Workbooks.Open("C:\Temp\name.xlsx")
   [B]Sheets("data").Select[/B]
[B]  Range("A1:G2000").Select[/B]
[B]  Selection.Delete Shift:=xlToLeft[/B]
Workbooks("name.xlsx").Close SaveChanges:=True

Running the macro messes up all funtions that targets those cells.

Like:
Code:
=DATEVALUE(MID(data![B]#REF[/B]!;4;2)&"."&LEFT(data![B]#REF[/B]!;2)&"."&RIGHT(data![B]#REF[/B]!;2))

PS. This really great code to get data from outlook is orginally: http://www.codeforexcelandoutlook.com/blog/2008/08/extract-calendar-data-from-outlook-into-excel/

Thank you!
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Can't you just use ClearContents instead of Delete?

Ofcourse! I feel stupid now :D Thank you for guiding me to right direction. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>

Changed code to:

Code:
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim myCalItems As Outlook.Items
Dim ItemstoCheck As Outlook.Items
Dim ThisAppt As Outlook.AppointmentItem<o:p></o:p>
Dim MyItem As Object<o:p></o:p>
Dim StringToCheck As String<o:p></o:p>
Set Mybook = Excel.Workbooks.Open("C:\Temp\name.xlsx")
Worksheets("data").Range("A1:G2000").ClearContents
Workbooks("name.xlsx").Close SaveChanges:=True
<o:p></o:p>
<o:p></o:p>
<o:p>Thank you!</o:p>
 
Upvote 0

Forum statistics

Threads
1,224,885
Messages
6,181,583
Members
453,055
Latest member
cope7895

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