Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Selecting Populate Cells

I want to format some cells in a spreadsheet using VBA from MS Access. The
formatting code I have is working fine (thanks to Bernie Deitrick) but the
range of cells populated with data will change over time. What code do I
need to detect the range of populated cells (there will never be gaps in the
data)?

Many thanks.

Keith.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Selecting Populate Cells

Use the CurrentRegion property of the range, eg

Dim myRange as Range
set myRange = Range("A1").CurrentRegion
myRange.Font.Size=12

assuming A1 is in the set of populated cells.

Cheers

On Jul 3, 9:48 pm, "Keith Wilby" wrote:
I want to format some cells in a spreadsheet using VBA from MS Access. The
formatting code I have is working fine (thanks to Bernie Deitrick) but the
range of cells populated with data will change over time. What code do I
need to detect the range of populated cells (there will never be gaps in the
data)?

Many thanks.

Keith.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Selecting Populate Cells

wrote in message
oups.com...
Use the CurrentRegion property of the range, eg

Dim myRange as Range
set myRange = Range("A1").CurrentRegion
myRange.Font.Size=12

assuming A1 is in the set of populated cells.


Perfect! Many thanks David.

Keith.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Selecting Populate Cells

Keith,

Again, it depends on which level object you have currently defined:

Dim oExcel As Excel.Application
Dim xlShtObj As Excel.Worksheet
Dim objRange As Excel.Range
.....

With xlShtObj
Set objRange = .Range(.Range("D3"), .Cells(Rows.Count,4).End(xlUp))
End With

will be the range of all cells in column D on the sheet object xlShtObj.

Of course, there are many ways of getting the same range:

With xlShtObj
Set objRange = .Range(.Range("D3"), .Cells(Rows.Count, 4).End(xlUp))
MsgBox objRange.Address
Set objRange = .Range(.Range("D3"), .Range("D3").End(xlDown))
MsgBox objRange.Address
Set objRange = Intersect(.Range("D3:D65536"), .UsedRange)
MsgBox objRange.Address
Set objRange = Intersect(.Range("D:D"), .Range("D3").CurrentRegion)
MsgBox objRange.Address
End With

and many other variations on those themes....

HTH,
Bernie
MS Excel MVP


"Keith Wilby" wrote in message ...
I want to format some cells in a spreadsheet using VBA from MS Access. The formatting code I have
is working fine (thanks to Bernie Deitrick) but the range of cells populated with data will change
over time. What code do I need to detect the range of populated cells (there will never be gaps in
the data)?

Many thanks.

Keith.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Selecting Populate Cells

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Keith,

Again, it depends on which level object you have currently defined:

Dim oExcel As Excel.Application
Dim xlShtObj As Excel.Worksheet
Dim objRange As Excel.Range
....

With xlShtObj
Set objRange = .Range(.Range("D3"), .Cells(Rows.Count,4).End(xlUp))
End With

will be the range of all cells in column D on the sheet object xlShtObj.

Of course, there are many ways of getting the same range:

With xlShtObj
Set objRange = .Range(.Range("D3"), .Cells(Rows.Count, 4).End(xlUp))
MsgBox objRange.Address
Set objRange = .Range(.Range("D3"), .Range("D3").End(xlDown))
MsgBox objRange.Address
Set objRange = Intersect(.Range("D3:D65536"), .UsedRange)
MsgBox objRange.Address
Set objRange = Intersect(.Range("D:D"), .Range("D3").CurrentRegion)
MsgBox objRange.Address
End With


Thanks very much for yet another great response Bernie. I've used David's
suggestion to select all populated cells to set the font size but what I
need now is to select all populated columns from, say, column J onwards to
set their width and apply conditional formatting. Which option would be
best suited?

Many thanks.

Keith.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Selecting Populate Cells

Keith,

Try

With xlShtObj
Set objRange = Intersect(.Range("J:IV"), .Range("J3").CurrentRegion)
End With

would work well, if there entirely blank rows and columns delineating the range you want to work
with. Otherwise,

With xlShtObj
Set objRange = Intersect(.Range("J:IV"), .UsedRange)
End With


HTH,
Bernie
MS Excel MVP


"Keith Wilby" wrote in message ...
"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Keith,

Again, it depends on which level object you have currently defined:

Dim oExcel As Excel.Application
Dim xlShtObj As Excel.Worksheet
Dim objRange As Excel.Range
....

With xlShtObj
Set objRange = .Range(.Range("D3"), .Cells(Rows.Count,4).End(xlUp))
End With

will be the range of all cells in column D on the sheet object xlShtObj.

Of course, there are many ways of getting the same range:

With xlShtObj
Set objRange = .Range(.Range("D3"), .Cells(Rows.Count, 4).End(xlUp))
MsgBox objRange.Address
Set objRange = .Range(.Range("D3"), .Range("D3").End(xlDown))
MsgBox objRange.Address
Set objRange = Intersect(.Range("D3:D65536"), .UsedRange)
MsgBox objRange.Address
Set objRange = Intersect(.Range("D:D"), .Range("D3").CurrentRegion)
MsgBox objRange.Address
End With


Thanks very much for yet another great response Bernie. I've used David's suggestion to select
all populated cells to set the font size but what I need now is to select all populated columns
from, say, column J onwards to set their width and apply conditional formatting. Which option
would be best suited?

Many thanks.

Keith.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Selecting Populate Cells

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Keith,

Try

With xlShtObj
Set objRange = Intersect(.Range("J:IV"), .Range("J3").CurrentRegion)
End With

would work well, if there entirely blank rows and columns delineating the
range you want to work with. Otherwise,

With xlShtObj
Set objRange = Intersect(.Range("J:IV"), .UsedRange)
End With



Perfect! Thanks Bernie.

Regards,
Keith.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Selecting Populate Cells

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Keith,

Try

With xlShtObj
Set objRange = Intersect(.Range("J:IV"), .Range("J3").CurrentRegion)
End With

would work well, if there entirely blank rows and columns delineating the
range you want to work with. Otherwise,

With xlShtObj
Set objRange = Intersect(.Range("J:IV"), .UsedRange)
End With



Just one last quickie Bernie, how do I adapt this

Set objRange = objXL.Intersect(objSht.Range("K:IV"), objSht.UsedRange)

such that it ignores the first row of the range? I've tried Range("K2:IV")
but that doesn't work (it doesn't help that I don't really know what that
snippet does).

Thanks as always.

Keith.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Selecting Populate Cells

Keith,

To ignore the first row of the range, just use

Set objRange = objXL.Intersect(objSht.Range("K2:IV65536"), objSht.UsedRange)

The string passed to the Range object ("K2:IV65536") is the same as if you selected that range in a
function call.

HTH,
Bernie
MS Excel MVP


"Keith Wilby" wrote in message ...
"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Keith,

Try

With xlShtObj
Set objRange = Intersect(.Range("J:IV"), .Range("J3").CurrentRegion)
End With

would work well, if there entirely blank rows and columns delineating the range you want to work
with. Otherwise,

With xlShtObj
Set objRange = Intersect(.Range("J:IV"), .UsedRange)
End With



Just one last quickie Bernie, how do I adapt this

Set objRange = objXL.Intersect(objSht.Range("K:IV"), objSht.UsedRange)

such that it ignores the first row of the range? I've tried Range("K2:IV") but that doesn't work
(it doesn't help that I don't really know what that snippet does).

Thanks as always.

Keith.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
auto populate different cells when selecting from drop down list. abitanga Excel Worksheet Functions 2 February 20th 09 11:44 PM
Selecting list to populate combo box gramps Excel Discussion (Misc queries) 2 August 11th 07 06:37 PM
Prevent other users from selecting next available auto-populate cell burl_rfc_h Excel Programming 1 March 8th 06 03:19 AM
how do populate empty cells with the contents of populated cells . Jim99 Excel Discussion (Misc queries) 6 April 21st 05 05:44 PM
Auto populate cells based on 2 cells division. Chance224 Excel Discussion (Misc queries) 0 April 4th 05 09:35 PM


All times are GMT +1. The time now is 05:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"