Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Reference columns using For each r in currentregion

I've tried using this for an if then type scenario but I get hung up trying
to reference the columns.
Something like

for each r in currentregion
If cell("A"+R+"").value = 6 then
cell( ---A + 6 columns-----).value = '=sum(A"+r+" / 6)'
Elseif cell("A"+r+"").value = "" then
cells(A"+r+":AA"+r+"").value = 3
Else
cells(A"+r+":BA"+r+"").value = '=sum(A" -------r minus 1
row--------" + A" + ---------r plus 3 rows-------")
end if
next r

There's more formula stuff that goes into it, but I can't seem to get the
row/column reference correct.

I will never know the exact column or row references prior to the begining
of code exectution. Right now I'm doing a select current region, count rows
and columns and then doing some really combersome variable declarations. Any
way to make it tighter?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Reference columns using For each r in currentregion

For Each r In ActiveCell.CurrentRegion
If r.Value = 6 Then
r.Offset(0, 6).Value = "=" & r.Value & "/6"
ElseIf r.Value = "" Then
r.Resize(, 27).Value = 3
Else
r.Resize(, 53).Formula = "=SUM(" & r.Offset(-1, 0).Address & ":" &
r.Offset(3, 0).Address & ")"
End If
Next r


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"RominallL" wrote in message
...
I've tried using this for an if then type scenario but I get hung up
trying
to reference the columns.
Something like

for each r in currentregion
If cell("A"+R+"").value = 6 then
cell( ---A + 6 columns-----).value = '=sum(A"+r+" / 6)'
Elseif cell("A"+r+"").value = "" then
cells(A"+r+":AA"+r+"").value = 3
Else
cells(A"+r+":BA"+r+"").value = '=sum(A" -------r minus 1
row--------" + A" + ---------r plus 3 rows-------")
end if
next r

There's more formula stuff that goes into it, but I can't seem to get the
row/column reference correct.

I will never know the exact column or row references prior to the begining
of code exectution. Right now I'm doing a select current region, count
rows
and columns and then doing some really combersome variable declarations.
Any
way to make it tighter?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Reference columns using For each r in currentregion

THANKS!!!

So it starts the active cell at the first column????

I ask because sometimes the current region might start on different columns.


"Bob Phillips" wrote:

For Each r In ActiveCell.CurrentRegion
If r.Value = 6 Then
r.Offset(0, 6).Value = "=" & r.Value & "/6"
ElseIf r.Value = "" Then
r.Resize(, 27).Value = 3
Else
r.Resize(, 53).Formula = "=SUM(" & r.Offset(-1, 0).Address & ":" &
r.Offset(3, 0).Address & ")"
End If
Next r


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"RominallL" wrote in message
...
I've tried using this for an if then type scenario but I get hung up
trying
to reference the columns.
Something like

for each r in currentregion
If cell("A"+R+"").value = 6 then
cell( ---A + 6 columns-----).value = '=sum(A"+r+" / 6)'
Elseif cell("A"+r+"").value = "" then
cells(A"+r+":AA"+r+"").value = 3
Else
cells(A"+r+":BA"+r+"").value = '=sum(A" -------r minus 1
row--------" + A" + ---------r plus 3 rows-------")
end if
next r

There's more formula stuff that goes into it, but I can't seem to get the
row/column reference correct.

I will never know the exact column or row references prior to the begining
of code exectution. Right now I'm doing a select current region, count
rows
and columns and then doing some really combersome variable declarations.
Any
way to make it tighter?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Reference columns using For each r in currentregion

It starts at the first cell in the current region surrounding the
activecell. That could be a row or column before the activecell.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"RominallL" wrote in message
...
THANKS!!!

So it starts the active cell at the first column????

I ask because sometimes the current region might start on different
columns.


"Bob Phillips" wrote:

For Each r In ActiveCell.CurrentRegion
If r.Value = 6 Then
r.Offset(0, 6).Value = "=" & r.Value & "/6"
ElseIf r.Value = "" Then
r.Resize(, 27).Value = 3
Else
r.Resize(, 53).Formula = "=SUM(" & r.Offset(-1, 0).Address & ":"
&
r.Offset(3, 0).Address & ")"
End If
Next r


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"RominallL" wrote in message
...
I've tried using this for an if then type scenario but I get hung up
trying
to reference the columns.
Something like

for each r in currentregion
If cell("A"+R+"").value = 6 then
cell( ---A + 6 columns-----).value = '=sum(A"+r+" / 6)'
Elseif cell("A"+r+"").value = "" then
cells(A"+r+":AA"+r+"").value = 3
Else
cells(A"+r+":BA"+r+"").value = '=sum(A" -------r minus 1
row--------" + A" + ---------r plus 3 rows-------")
end if
next r

There's more formula stuff that goes into it, but I can't seem to get
the
row/column reference correct.

I will never know the exact column or row references prior to the
begining
of code exectution. Right now I'm doing a select current region, count
rows
and columns and then doing some really combersome variable
declarations.
Any
way to make it tighter?






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
Select first row of currentregion vba Excel Programming 4 July 19th 06 01:16 PM
currentregion flow23 Excel Discussion (Misc queries) 13 November 23rd 05 05:02 PM
CurrentRegion less one Row GregR Excel Programming 8 November 7th 05 05:16 PM
CurrentRegion Steph[_3_] Excel Programming 2 August 10th 04 07:00 PM
CurrentRegion Failure. Please help! John T Ingato Excel Programming 2 November 9th 03 11:12 PM


All times are GMT +1. The time now is 05:17 AM.

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

About Us

"It's about Microsoft Excel"