Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Help with Simple Excel Loop

Hi,

Could someone please provide some sample vba code in excel to do the
following:

Loop for n rows:
Check data in cell x
if cell x 0 then copy contents of cell x and cell y to an array

Then have one string variable which has the contents of array. For
example,

1 Test
2 Test Two
0 Nothing
1 Test Four

Each number on the left hand side is in a cell - the text is also in a
cell next to the number.

So String would output:
1 Test
2 Test Two
1 Test Four

Any help will be much appreciated.

Thanks,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Help with Simple Excel Loop

Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim iLastRow As Long
Dim tmp As String

With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i, TEST_COLUMN).Value 0 Then
tmp = tmp & .Cells(i, TEST_COLUMN).Value & " " & _
.Cells(i, TEST_COLUMN).Offset(0, 1).Value & vbNewLine
End If
Next i

End With

MsgBox tmp

End Sub

--
---
HTH

Bob

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



wrote in message
ps.com...
Hi,

Could someone please provide some sample vba code in excel to do the
following:

Loop for n rows:
Check data in cell x
if cell x 0 then copy contents of cell x and cell y to an array

Then have one string variable which has the contents of array. For
example,

1 Test
2 Test Two
0 Nothing
1 Test Four

Each number on the left hand side is in a cell - the text is also in a
cell next to the number.

So String would output:
1 Test
2 Test Two
1 Test Four

Any help will be much appreciated.

Thanks,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Help with Simple Excel Loop

Superb! Thanks!

On 30 Apr, 12:50, "Bob Phillips" wrote:
Public Sub ProcessData()
Const TEST_COLUMN As String = "A" '<=== change to suit
Dim i As Long
Dim iLastRow As Long
Dim tmp As String

With ActiveSheet

iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 1 To iLastRow
If .Cells(i, TEST_COLUMN).Value 0 Then
tmp = tmp & .Cells(i, TEST_COLUMN).Value & " " & _
.Cells(i, TEST_COLUMN).Offset(0, 1).Value & vbNewLine
End If
Next i

End With

MsgBox tmp

End Sub

--
---
HTH

Bob

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

wrote in message

ps.com...

Hi,


Could someone please provide some sample vba code in excel to do the
following:


Loop for n rows:
Check data in cell x
if cell x 0 then copy contents of cell x and cell y to an array


Then have one string variable which has the contents of array. For
example,


1 Test
2 Test Two
0 Nothing
1 Test Four


Each number on the left hand side is in a cell - the text is also in a
cell next to the number.


So String would output:
1 Test
2 Test Two
1 Test Four


Any help will be much appreciated.


Thanks,



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
Simple Loop Help Please pianoman[_24_] Excel Programming 0 May 24th 06 02:34 PM
Simple Loop Help Please HBF Excel Programming 0 May 24th 06 02:30 PM
Simple loop problem Christy Excel Programming 6 December 16th 05 04:30 PM
Simple loop? bushtor Excel Programming 3 September 13th 05 01:45 PM
Some help w/ simple loop, please? terry b Excel Programming 6 February 6th 05 06:17 PM


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