Clearing a range on another worksheet

Yoepy

New Member
Joined
Feb 22, 2015
Messages
44
I'd appreciate some help on probably a simple problem.

I want to clear the contents on Sheet1 of a range from row 15 to 51 but the column number is a variable based on a Input box (Dim myValue As Integer).

When I run the VBA from the Sheet1 it works fine as follows

Code:
ActiveSheet.Range(Cells(15, (myValue)), Cells(51, (myValue))).ClearContents

But, I need to run it from another sheet.

Code:
Worksheets("Sheet1").Range(Cells(15, (myValue)), Cells(51, (myValue))).ClearContents

This doesn't work. What an I doing wrong?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Please post ALL the code you are using
 
Upvote 0
Make sure you are using the col Number and not the letter !

Code:
myval = InputBox("which column number do you want to use ??")
Worksheets("Sheet1").Range(Cells(15, myval), Cells(51, myval)).ClearContents
 
Upvote 0
Code:
Dim myValue As Integer 
myValue = Application.InputBox("Which range to delete?")
Worksheets("Sheet1").Range(Cells(15, (myValue)), Cells(51, (myValue))).ClearContents
 
Last edited:
Upvote 0
Yes I did Michael. But it's still not working. I'm in the process of deleting unrelated code to see if something else is causing the problem.


Thanks though.
 
Upvote 0
Hmm, works fine for me !
1. are you on the correct sheet
2. Is the sheet protected
3. Is the code in a module, worksheet, or This Workbook
4. how are you firing the code
 
Upvote 0
Thanks Michael. Your's did work (as did mine) when I fixed an unrelated piece of code.

Appreciate you pointing me in the right direction - that is look for something else.
 
Upvote 0
Glad to help and thx for the feedback...(y)
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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