About deleting variable rows

muhittinemmi

New Member
Joined
Jun 20, 2023
Messages
19
VBA Code:
Sub Makro3()
    Range("A10:E23").Select
    Selection.ClearContents
End Sub

I don't know if such a thing is possible but
Can I add the contents of cell I3 instead of e23 because row e23 is variable?
Since the number of rows is variable, cell I3 shows which row column e is in.
Example
I3= E23 or I3 = E35... etc.

I tried something like below but it didn't work

VBA Code:
Sub Makro3()
Range("A10:(Range("I3").Value)").Select
Selection.ClearContents
End Sub
 

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).
Try:
VBA Code:
Sub Makro3()
Range("A10:" & Range("I3").Value).ClearContents
End Sub
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0
Try:
VBA Code:
Sub Makro3()
Range("A10:" & Range("I3").Value).ClearContents
End Sub
It's not related to the topic, but if I want to copy this field, how should I change the code?
I added .copy instead of .ClearContents but couldn't get it to work
 
Upvote 0
I added .copy instead of .ClearContents but couldn't get it to work
You mean like this:
VBA Code:
Range("A10:" & Range("I3").Value).Copy
then it should work. Can you explain 'but couldn't get it to work'?
 
Upvote 0
It gives the following error
Runtime-time error '1004'
Method 'Range' of object'_global' failed
and it stopped at this line?
VBA Code:
Range("A10:" & Range("I3").Value).Copy
Not sure why, can you post the whole code?
What is Range("I3").Value?
 
Upvote 0
The problem is due to the value in I3.

Thanks for information.

Sorry for taking your time for such a simple thing.
 
Upvote 0

Forum statistics

Threads
1,215,540
Messages
6,125,409
Members
449,223
Latest member
Narrian

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