Cell references change after running macro

rvelt1213

New Member
Joined
Apr 13, 2022
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I have a spreadsheet that emailed orders are pasted to a specific cell. A macro is then run to populate a grid, basically rearranging the information to then be copy/pasted onto a different spreadsheet. The problem is - after I run the macro, all of the cell references in the grid change to #REF!. I have never had this happen before and cannot figure out how to make the cell references stay put! Any suggestions would be appreciated!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Suggestion: show the macro and the layout of your sheet, elsewise, send us a crystal ball.
 
Upvote 0
The references in A2, F2:L2 and M2:N6 are what keep changing. The order information is pasted into A8 and varies in length.

FedEx Web Order input.xlsm
ABCDEFGHIJKLMN
2Order #8/25/2022FedEx#N/A#N/A#N/A#N/A#N/A#N/A#N/A  
3  
4  
5  
6  
ARC orders
Cell Formulas
RangeFormula
A2A2="Order #"&RIGHT(A8,6)
C2C2=TODAY()
F2F2=VLOOKUP("Ship Attn",$A$8:$B$29,2,FALSE)
G2G2=VLOOKUP("Ship Address",$A$8:$B$29,2,FALSE)
H2H2=VLOOKUP("Ship CSZ",$A$8:$C$29,3,FALSE)
I2I2=VLOOKUP("Ship CSZ",$A$8:$D$29,4,FALSE)
J2J2=VLOOKUP("Ship CSZ",$A$8:$E$29,5,FALSE)
K2K2=VLOOKUP("Phon*",$A$8:$B$29,2,FALSE)
L2L2=VLOOKUP("Ship To",$A$8:$B$29,2,FALSE)
M2M2=IF($B$34="","",$B$34)
N2N2=IF($B$33="","",$B$33)
M3M3=IF($B$38="","",$B$38)
N3N3=IF($B$37="","",$B$37)
M4M4=IF($B$42="","",$B$42)
N4N4=IF($B$41="","",$B$41)
M5M5=IF($B$46="","",$B$46)
N5N5=IF($B$45="","",$B$45)
M6M6=IF($B$50="","",$B$50)
N6N6=IF($B$49="","",$B$49)


And the macros:

Sub TrimSpacesType1()
'
' TrimSpacesType1 Macro
'

'
Range("B8").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=TRIM(RC[-1])"
Range("B8").Select
Selection.AutoFill Destination:=Range("B8:B46"), Type:=xlFillDefault
Range("B8:B46").Select
ActiveWindow.SmallScroll Down:=-14
Selection.Copy
Range("A8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B8:B46").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
End Sub
Sub TTCType1()
'
' TTCType1 Macro
'

'
Range("A10:A46").Select
Selection.TextToColumns Destination:=Range("A10"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:=":", FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True
Range("B25").Select
Selection.TextToColumns Destination:=Range("B25"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=True, Other:=False, OtherChar _
:=":", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1)), _
TrailingMinusNumbers:=True
End Sub
Sub TrimPart()
'
' TrimPart Macro
'

'
ActiveWindow.SmallScroll Down:=9
Range("B32:B52").Select
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
ActiveWindow.SmallScroll Down:=-21
End Sub


Sub Type1()
Call TrimSpacesType1
Call TTCType1
Call TrimPart
End Sub
Sub DeleteOrder()
'
' DeleteOrder Macro
'

'
Range("A8:F107").Select
Selection.ClearContents
ActiveWindow.SmallScroll Down:=-73
End Sub
 
Upvote 0
That happens because you are deleting the cells which are recalled in those formulas. In macro 'TrimSpacesType1' nstead of deleting clear the contents.
VBA Code:
'Selection.Delete Shift:=xlUp
Selection.ClearContents
 
Upvote 0
Solution
That happens because you are deleting the cells which are recalled in those formulas. In macro 'TrimSpacesType1' nstead of deleting clear the contents.
VBA Code:
'Selection.Delete Shift:=xlUp
Selection.ClearContents
Brilliant!!!! I had to change my "DeleteOrder" macro to Clear Contents rather than deleting, but didn't see the one in "TrimSpacesType1".

I may have yelled out loud when it worked after updating! It was a very exciting moment!! Thank you so much 😁
 
Upvote 0
In fact, I saw that you had used 'ClearContents' elsewhere and I said to myself "why not here too?"; now I understand :).
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,552
Members
449,088
Latest member
davidcom

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