Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating a loop


I am trying to create a loop that:

1. Starts on Sheet1 at cell A10 and loops down colum A until it finds
and empty cell. Could somebody please point me in the right direction,
I am starting to loose my mind.

Thank you in advance.
Simon.


--
shart
------------------------------------------------------------------------
shart's Profile: http://www.excelforum.com/member.php...o&userid=29563
View this thread: http://www.excelforum.com/showthread...hreadid=492650

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Creating a loop

Option Explicit
Sub test()
Dim target As Range

Set target = GetFirstEmpty(Range("A10"))
target.Select
MsgBox target.Address

End Sub

Function GetFirstEmpty(StartFrom As Range) As Range

Dim target As Range

If StartFrom = "" Then
Set GetFirstEmpty = StartFrom
Else
Set GetFirstEmpty = StartFrom.End(xlDown).Offset(1)
End If

End Function


"shart" wrote:


I am trying to create a loop that:

1. Starts on Sheet1 at cell A10 and loops down colum A until it finds
and empty cell. Could somebody please point me in the right direction,
I am starting to loose my mind.

Thank you in advance.
Simon.


--
shart
------------------------------------------------------------------------
shart's Profile: http://www.excelforum.com/member.php...o&userid=29563
View this thread: http://www.excelforum.com/showthread...hreadid=492650


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating a loop


Thank You,

My next question:

Now that the code is looping through the 1st column, I would like to
start copying data from that row to other sheets. I would also like to
input formuls. ( I have a formula already)

eg.

Sheet1(A10) copied to Sheet2(A10)
Sheet1(B10) copied to Sheet2(B10)
Put formula (=Sheet1!D10&" "&Sheet1!F10&" "&Sheet1!G10) into
Sheet2(C10)
(I would like to copy this from a previous cell in the same column
so that the 10's
change to 11's etc.)
Put Formula (=Sheet1!B10) into Sheet2(B10)


If I have these, I am pretty sure I can work the rest out.

Thank you in advance
Simon Hart.


--
shart
------------------------------------------------------------------------
shart's Profile: http://www.excelforum.com/member.php...o&userid=29563
View this thread: http://www.excelforum.com/showthread...hreadid=492650

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Creating a loop

If I understand correctly then I am not sure you need a loop at all. You
could just find the last used row in your range on sheet1 (I have done
this by starting at Cell A10 and moving down to first blank row) and
then use this variable to set the formulae on sheet2 eg:

Sub cpy()
Dim eRow As Long
eRow = Sheets("Sheet1").Range("A10").End(xlDown).Row
With Sheets("Sheet2")
.Range("A10:B" & eRow).FormulaR1C1 = _
"=Sheet1!RC"
.Range("C10:C" & eRow).FormulaR1C1 = _
"=Sheet1!RC[1]&"" ""&Sheet1!RC[3]&"" ""&Sheet1!RC[4]"
End With
End Sub

Hope this helps
Rowan

shart wrote:
Thank You,

My next question:

Now that the code is looping through the 1st column, I would like to
start copying data from that row to other sheets. I would also like to
input formuls. ( I have a formula already)

eg.

Sheet1(A10) copied to Sheet2(A10)
Sheet1(B10) copied to Sheet2(B10)
Put formula (=Sheet1!D10&" "&Sheet1!F10&" "&Sheet1!G10) into
Sheet2(C10)
(I would like to copy this from a previous cell in the same column
so that the 10's
change to 11's etc.)
Put Formula (=Sheet1!B10) into Sheet2(B10)


If I have these, I am pretty sure I can work the rest out.

Thank you in advance
Simon Hart.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Creating a loop


Thank You. The code works perfectly. From your code I was able to
create the code for the rest of the sheet.

I have another question.

One of the lines looks like this:


Code:
--------------------
.Range("D10:D" & eRow).FormulaR1C1 = _
"=IF(LEN(Global!RC[1])0,Global!RC[1],"""")"
--------------------


I would like to add some VBA that changes the formatting of the cell if
Global!RC[1] is greater than Global!RC[0]
(i.e. if the sale price is greater than the normal price, change the
background color on Sheet2(D10) to red. This would make it easy to spot
errors in Global)

Thank you in advance.
Simon.

Ps. Thank you for all the help so far, without it I would still be
stuck copying and pasting from various VBA books and tutorials trying
to figure out what is what.

Other goals for this little application (getting there):
1. Exporting Sheet2 as a CSV file.


--
shart
------------------------------------------------------------------------
shart's Profile: http://www.excelforum.com/member.php...o&userid=29563
View this thread: http://www.excelforum.com/showthread...hreadid=492650



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Creating a loop

That may need a loop. Somthing like:

Dim i As Long
With Sheets("Sheet2")
.Range("D10:D" & eRow).FormulaR1C1 = _
"=IF(LEN(Global!RC[1])0,Global!RC[1],"""")"
For i = 1 To eRow
If Sheets("Global").Range("E" & i) _
Sheets("Global").Range("D" & i) Then
.Range("D" & i).Interior.ColorIndex = 3
End If
Next i
End With

For the export to CSV see JE McGimpsey's notes at:

http://www.mcgimpsey.com/excel/textfiles.html

Hope this helps
Rowan

shart wrote:
Thank You. The code works perfectly. From your code I was able to
create the code for the rest of the sheet.

I have another question.

One of the lines looks like this:


Code:
--------------------
.Range("D10:D" & eRow).FormulaR1C1 = _
"=IF(LEN(Global!RC[1])0,Global!RC[1],"""")"
--------------------


I would like to add some VBA that changes the formatting of the cell if
Global!RC[1] is greater than Global!RC[0]
(i.e. if the sale price is greater than the normal price, change the
background color on Sheet2(D10) to red. This would make it easy to spot
errors in Global)

Thank you in advance.
Simon.

Ps. Thank you for all the help so far, without it I would still be
stuck copying and pasting from various VBA books and tutorials trying
to figure out what is what.

Other goals for this little application (getting there):
1. Exporting Sheet2 as a CSV file.


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
creating a loop JakeShipley2008 Excel Discussion (Misc queries) 2 September 9th 08 02:17 PM
Creating a loop JakeShipley2008 Excel Discussion (Misc queries) 1 September 8th 08 10:26 PM
Need help creating Loop Jenny B. Excel Discussion (Misc queries) 3 February 14th 07 11:26 PM
Need Help With Creating A Loop zero635[_8_] Excel Programming 3 October 29th 05 08:58 PM
Creating a For Loop Justin Ragsdale Excel Programming 5 May 23rd 04 10:40 PM


All times are GMT +1. The time now is 01:33 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"