referencing cellswith values in them

Pjam

Board Regular
Joined
Jun 4, 2008
Messages
139
anyone know how to reference cells with values in them, no matter where they are on the spreadsheet?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

mvptomlinson

Well-known Member
Joined
Mar 10, 2008
Messages
2,638
Not sure if this is what you mean, but in VBA you could use something like this, which would select all cells with constants (text/number/errors/logical values entered manually, not using formulas) in the range A1:Z100:
Code:
Range("A1:Z100").SpecialCells(xlCellTypeConstants, 23).Select
Or this, to select all cells with formulas that result in text/numbers/errors/logicals:
Code:
Range("A1:Z100").SpecialCells(xlCellTypeFormulas, 23).Select
These perform the same function as using F5-->Special-->Constants or F5-->Special-->Formulas.
 
Upvote 0

Pjam

Board Regular
Joined
Jun 4, 2008
Messages
139
no i dontwant to use a range, because the values could be in any cell throughout the spreadsheet, so how do i reference code to any cell in a sheet that has a value in it?

the only thing i have used so far us

For Each c In Sheets("sheet1").UsedRange.Cells<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
If Not c = Empty Then<o:p></o:p>
 
Upvote 0

mvptomlinson

Well-known Member
Joined
Mar 10, 2008
Messages
2,638
Umm, then switch out Range("A1:Z100") with UsedRange

Using SpecialCells will be MUCH quicker than looping through every cell in your sheet.
 
Upvote 0

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Range("A1:Z100").SpecialCells(xlCellTypeConstants, 23).Select
Range("A1:Z100").SpecialCells(xlCellTypeFormulas, 23).Select

You don't need "23" when you are referring to all types.
 
Upvote 0

mvptomlinson

Well-known Member
Joined
Mar 10, 2008
Messages
2,638
Good to know, Jindon. I just copied what Excel's macro recorder spit out. I tested a few others and the number changed, so I left it. Thanks.
 
Upvote 0

Forum statistics

Threads
1,191,482
Messages
5,986,843
Members
440,053
Latest member
jhollingworth

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
Top