Selection.ClearContents - VBA

j4ymf

Well-known Member
Joined
Apr 28, 2003
Messages
740
Office Version
  1. 365
Platform
  1. Windows
hello all

im trying to clear some cells using VBA
the first ones work on the run to product line , but why cant i get the others to work?
do i need a link or somthing to link them together ?

Code:
'RUN TO PRODUCT
      Range("J25,J38,J51,J64,J77,J90,J103,J116,J129,J142,J155,J168,J181,J194,J207").Select
      Selection.ClearContents

'CLEAR COMMENTS
      Range("J24,J37,J50,J63,J76,J89,J102,J115,J128,J141,J154,J167,J180,J193,J206").Select
      Selection.ClearContents
   
'CLEAR COMMENTS
      Range("J23,J36,J49,J62,J75,J87,J101,J114,J127,J140,J153,J166,J179,J192,J205").Select
      Selection.ClearContents


many thanks jason
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Do you mean CLEAR COMMENTS as opposed to CLEAR CONTENTS?

Code:
'RUN TO PRODUCT
      Range("J25,J38,J51,J64,J77,J90,J103,J116,J129,J142,J155,J168,J181,J194,J207").ClearContents

'CLEAR COMMENTS
      Range("J24,J37,J50,J63,J76,J89,J102,J115,J128,J141,J154,J167,J180,J193,J206").ClearComments
   
'CLEAR COMMENTS
      Range("J23,J36,J49,J62,J75,J87,J101,J114,J127,J140,J153,J166,J179,J192,J205").ClearComments
 
Upvote 0
Jason - can you be more specific about what is not working?

When I copied your code into a workbook, the code seemed to work properly. The values from cells J23, J24, J25, J36, J37, J38 ... etc were all cleared. Is there something else that you are trying to clear from the cells besides their values?
 
Upvote 0
For me it's running in the active sheet: CONTENTS REMOVED
You could simplify using
Code:
      Range("J25,J38,J51,J64,J77,J90,J103,J116,J129,J142,J155,J168,J181,J194,J207").ClearContents
 
Upvote 0
hello sorry folks

Im trying to clear the contents on all the cells specified.

The run to product line works, but the two clear comment lines don't clear the contents.

thanks jason
 
Upvote 0
is it because im trying to delete in a merge cell?
 
Upvote 0
MANY THANKS FOLKS :)

PCL thanks and it was because i had a couple of merged cells in it, sorry for the trouble

jason
 
Upvote 0

Forum statistics

Threads
1,213,522
Messages
6,114,112
Members
448,549
Latest member
brianhfield

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