defing a range with a varying size...

RobbieC

Active Member
Joined
Dec 14, 2016
Messages
376
Office Version
  1. 2010
Platform
  1. Windows
Hi there, I need to define a range on a sheet in column A, eg. A1:A15 (15 values)

However, the number of values varies depending upon what has been inputted. Is there a way to define the range up to the last cell with a value and discount anything after?

If you can point me in the right direction, that's be brilliant. Thanks
 
the macro works for any sheet unchanged it only works on the currently active worksheet

so if you click sheet 7 tab and run the original macro it will work on sheet 7


if you want to be on sheet one but have code run on sheet 7 that can be done
 
Last edited:
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Yes please. I need to run the code from different sheets than sheet7 - sheet7 is just where my data is being stored and isn't 'visible' and the contents are just referenced via other pages

Really appreciate your help Troub :)
 
Upvote 0
ok try this you need to change with sheet name to the actual sheet name i have marked in red it will then only delete blanks from that sheet

Code:
Option Explicit
 
Sub DeleteBlanks()
    Dim intCol As Integer

With Worksheets("[COLOR=#ff0000]SheetName[/COLOR]")
     
    For intCol = 1 To 1 'cols A to change for number of columns
        Range(Cells(2, intCol), Cells(353, intCol)). _
        SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
    Next intCol
    
End With
    
End Sub
 
Last edited:
Upvote 0
hrm, I changed the code and changed the sheetname.

It didn't throw an error, but it didn't remove the blank cell. It does work tho if I'm on the active sheet... puzzling
 
Upvote 0
You need some periods/full stops

Code:
Sub DeleteBlanks()
    Dim intCol As Integer

With Worksheets("SheetName")
     
    For intCol = 1 To 1 'cols A to change for number of columns
        [COLOR="#FF0000"].[/COLOR]Range([COLOR="#FF0000"].[/COLOR]Cells(2, intCol),[COLOR="#FF0000"] .[/COLOR]Cells(353, intCol)). _
        SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
    Next intCol
    
End With
    
End Sub
 
Upvote 0
ha, BRILLIANT!

Thanks guys, that has done the trick - it works perfectly now!

Really appreciate your help - have a great weekend :)
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,616
Members
449,238
Latest member
wcbyers

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