Dynamic Range selection

earthworm

Well-known Member
Joined
May 19, 2009
Messages
759
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
I am using the below macro to apply X on empty cell in column Heading 7 . However when i play the macro this does not work and its not dynamic despite of using relative mode during macro recording . The Macro length needs to be dynamic . Please assist.


S.noHeading 4Heading 5Heading 6Heading 7
1X
2X
3X
4d
5X
6X
7X
8G
10​

VBA Code:
Sub Macro4()
'
' Macro4 Macro
'

'
    Range("A1").Select
    Selection.End(xlDown).Select
    ActiveCell.Offset(-8, 4).Range("A1:A9").Select
    ActiveCell.Offset(0, 4).Range("A1").Activate
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.FormulaR1C1 = "X"
    Range("A1").Select
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
How about
VBA Code:
Sub earthworm()
   Range("E1:E" & Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlBlanks).Value = "X"
End Sub
 
Upvote 0
I tried the above but its not dynamic . Example the macro will not function if the value is non numeric in S.no . I tried COUNTA in macro but its not working.
Secondly the starting position of range in in column E must be as per last value in s.no. If there is any value missing in last cell of column E then this macro is not working correctly. Please suggest and also share step by step . I wasted hours to understand but still no clue.
 
Upvote 0
Sorry but I don't understand what you are saying.
The code I posted will put an X in every empty cell in col E down to the last row of data in col A.
 
Upvote 0
Sorry but I don't understand what you are saying.
The code I posted will put an X in every empty cell in col E down to the last row of data in col A.
Please extend the rows and input any value in s.noand empty the last value in column E and try running the macro . You will get the picture.
 
Upvote 0
I get an X in every empty cell in col E until the last row with a value in col A.
Are the blank cells in col E actually empty?
 
Upvote 0
Please try the macro you shared on below

S.noHeading 4Heading 5Heading 6Heading 7
1X
2X
3X
4d
5X
6X
7X
8G10
G
H
Y
 
Upvote 0
How about
VBA Code:
Sub earthworm()
   Range("E1:E" & Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlBlanks).Value = "X"
End Sub
 
Upvote 0
PER
How about
VBA Code:
Sub earthworm()
   Range("E1:E" & Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlBlanks).Value = "X"
End Sub

Perfect . I also searched from youtube and found this which is also good in selection . please advice is this good too ?

VBA Code:
 Sub dynamic_range()
    dy_range = ActiveSheet.UsedRange.Rows.Count
    Range("E1:E" & dy_range).Select
    End Sub
 
Upvote 0
There is very rarely any need to use select.
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,438
Members
449,083
Latest member
Ava19

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