PC Review


Reply
Thread Tools Rate Thread

Amend Code Help Please

 
 
Paul Black
Guest
Posts: n/a
 
      21st Aug 2007
Hi everyone,

I have the following code ...

Option Explicit
Option Base 1

Public Sub Test()
Dim RowData As Range
Dim C As Long
Dim CombData As String
Dim CombNum As Integer

CombNum = 1 <---------
For Each RowData In ActiveSheet.UsedRange.Rows
With RowData
If C > 0 Then CombNum = CombNum + 1
CombData = ""
For C = 1 To 5
CombData = CombData & .Cells(1, C).Value & ","
Next C
CombData = CombData & .Cells(1, 6).Value
Debug.Print "Set " & CombNum & "," & CombData
End With
Next RowData

End Sub

.... which does produce the right information in the right format.
I would like to amend the code to pick up the groups on a sheet named
"Groups" and in Cells "B3:G?". The groups could be 1 to whatever.
The other thing is that I have had to set the CombNum to 1 when I
think it should start at zero.
If there is a better way to code this I would appreciate any pointers.

Thanks in dvance.
All the Best.
Paul

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      21st Aug 2007
Public Sub Test()
Dim RowData As Range
Dim C As Long
Dim CombData As String
Dim CombNum As Integer

For Each RowData In ActiveSheet.UsedRange.Rows
With RowData
If RowData.Row > 2 Then
CombNum = CombNum + 1
CombData = ""
For C = 2 To 6
CombData = CombData & .Cells(1, C).Value & ","
Next C
CombData = CombData & .Cells(1, 7).Value
Debug.Print "Set " & CombNum & "," & CombData
End If
End With
Next RowData
End Sub



--
---
HTH

Bob

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



"Paul Black" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi everyone,
>
> I have the following code ...
>
> Option Explicit
> Option Base 1
>
> Public Sub Test()
> Dim RowData As Range
> Dim C As Long
> Dim CombData As String
> Dim CombNum As Integer
>
> CombNum = 1 <---------
> For Each RowData In ActiveSheet.UsedRange.Rows
> With RowData
> If C > 0 Then CombNum = CombNum + 1
> CombData = ""
> For C = 1 To 5
> CombData = CombData & .Cells(1, C).Value & ","
> Next C
> CombData = CombData & .Cells(1, 6).Value
> Debug.Print "Set " & CombNum & "," & CombData
> End With
> Next RowData
>
> End Sub
>
> ... which does produce the right information in the right format.
> I would like to amend the code to pick up the groups on a sheet named
> "Groups" and in Cells "B3:G?". The groups could be 1 to whatever.
> The other thing is that I have had to set the CombNum to 1 when I
> think it should start at zero.
> If there is a better way to code this I would appreciate any pointers.
>
> Thanks in dvance.
> All the Best.
> Paul
>



 
Reply With Quote
 
Paul Black
Guest
Posts: n/a
 
      21st Aug 2007
Thanks Bob,

I amended your code slightly to get the number of the group at the
beginning and ended up with this :-

Public Sub Test()
Dim RowData As Range
Dim C As Long
Dim CombData As String
Dim CombNum As Integer

For Each RowData In Worksheets("Data").UsedRange.Rows
With RowData
If RowData.Row > 2 Then ' Combinations start in cell "B3"
CombNum = CombNum + 1
CombData = ""
For C = 1 To 5
CombData = CombData & .Cells(1, C).Value & ","
Next C
CombData = CombData & .Cells(1, 6).Value
Debug.Print "Set " & CombNum & "," & CombData
End If
End With
Next RowData

End Sub

Thanks Again.
All the Best.
Paul

On Aug 21, 11:26 am, "Bob Phillips" <bob....@somewhere.com> wrote:
> Public Sub Test()
> Dim RowData As Range
> Dim C As Long
> Dim CombData As String
> Dim CombNum As Integer
>
> For Each RowData In ActiveSheet.UsedRange.Rows
> With RowData
> If RowData.Row > 2 Then
> CombNum = CombNum + 1
> CombData = ""
> For C = 2 To 6
> CombData = CombData & .Cells(1, C).Value & ","
> Next C
> CombData = CombData & .Cells(1, 7).Value
> Debug.Print "Set " & CombNum & "," & CombData
> End If
> End With
> Next RowData
> End Sub
>
> --
> ---
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Paul Black" <paul_blac...@hotmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > Hi everyone,

>
> > I have the following code ...

>
> > Option Explicit
> > Option Base 1

>
> > Public Sub Test()
> > Dim RowData As Range
> > Dim C As Long
> > Dim CombData As String
> > Dim CombNum As Integer

>
> > CombNum = 1 <---------
> > For Each RowData In ActiveSheet.UsedRange.Rows
> > With RowData
> > If C > 0 Then CombNum = CombNum + 1
> > CombData = ""
> > For C = 1 To 5
> > CombData = CombData & .Cells(1, C).Value & ","
> > Next C
> > CombData = CombData & .Cells(1, 6).Value
> > Debug.Print "Set " & CombNum & "," & CombData
> > End With
> > Next RowData

>
> > End Sub

>
> > ... which does produce the right information in the right format.
> > I would like to amend the code to pick up the groups on a sheet named
> > "Groups" and in Cells "B3:G?". The groups could be 1 to whatever.
> > The other thing is that I have had to set the CombNum to 1 when I
> > think it should start at zero.
> > If there is a better way to code this I would appreciate any pointers.

>
> > Thanks in dvance.
> > All the Best.
> > Paul- Hide quoted text -

>
> - Show quoted text -



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      21st Aug 2007
I thought you wanted B:G not A:F?

--
---
HTH

Bob

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



"Paul Black" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks Bob,
>
> I amended your code slightly to get the number of the group at the
> beginning and ended up with this :-
>
> Public Sub Test()
> Dim RowData As Range
> Dim C As Long
> Dim CombData As String
> Dim CombNum As Integer
>
> For Each RowData In Worksheets("Data").UsedRange.Rows
> With RowData
> If RowData.Row > 2 Then ' Combinations start in cell "B3"
> CombNum = CombNum + 1
> CombData = ""
> For C = 1 To 5
> CombData = CombData & .Cells(1, C).Value & ","
> Next C
> CombData = CombData & .Cells(1, 6).Value
> Debug.Print "Set " & CombNum & "," & CombData
> End If
> End With
> Next RowData
>
> End Sub
>
> Thanks Again.
> All the Best.
> Paul
>
> On Aug 21, 11:26 am, "Bob Phillips" <bob....@somewhere.com> wrote:
>> Public Sub Test()
>> Dim RowData As Range
>> Dim C As Long
>> Dim CombData As String
>> Dim CombNum As Integer
>>
>> For Each RowData In ActiveSheet.UsedRange.Rows
>> With RowData
>> If RowData.Row > 2 Then
>> CombNum = CombNum + 1
>> CombData = ""
>> For C = 2 To 6
>> CombData = CombData & .Cells(1, C).Value & ","
>> Next C
>> CombData = CombData & .Cells(1, 7).Value
>> Debug.Print "Set " & CombNum & "," & CombData
>> End If
>> End With
>> Next RowData
>> End Sub
>>
>> --
>> ---
>> HTH
>>
>> Bob
>>
>> (there's no email, no snail mail, but somewhere should be gmail in my
>> addy)
>>
>> "Paul Black" <paul_blac...@hotmail.com> wrote in message
>>
>> news:(E-Mail Removed)...
>>
>>
>>
>> > Hi everyone,

>>
>> > I have the following code ...

>>
>> > Option Explicit
>> > Option Base 1

>>
>> > Public Sub Test()
>> > Dim RowData As Range
>> > Dim C As Long
>> > Dim CombData As String
>> > Dim CombNum As Integer

>>
>> > CombNum = 1 <---------
>> > For Each RowData In ActiveSheet.UsedRange.Rows
>> > With RowData
>> > If C > 0 Then CombNum = CombNum + 1
>> > CombData = ""
>> > For C = 1 To 5
>> > CombData = CombData & .Cells(1, C).Value & ","
>> > Next C
>> > CombData = CombData & .Cells(1, 6).Value
>> > Debug.Print "Set " & CombNum & "," & CombData
>> > End With
>> > Next RowData

>>
>> > End Sub

>>
>> > ... which does produce the right information in the right format.
>> > I would like to amend the code to pick up the groups on a sheet named
>> > "Groups" and in Cells "B3:G?". The groups could be 1 to whatever.
>> > The other thing is that I have had to set the CombNum to 1 when I
>> > think it should start at zero.
>> > If there is a better way to code this I would appreciate any pointers.

>>
>> > Thanks in dvance.
>> > All the Best.
>> > Paul- Hide quoted text -

>>
>> - Show quoted text -

>
>



 
Reply With Quote
 
Paul Black
Guest
Posts: n/a
 
      21st Aug 2007
Hi Bob,

Yes, I want "B3:G?" whatever, but I wanted it to output the
combinations in the format ...

Set 1,1,2,3,4,5,6
Set 2,1,2,3,7,8,9
Set 3,3,5,6,7,8,9

.... where the first number after the Set is the combination number and
the other six numbers are the 6 number combination.

Thanks in Advance.
All the Best.
Paul

On Aug 21, 1:09 pm, "Bob Phillips" <bob....@somewhere.com> wrote:
> I thought you wanted B:G not A:F?
>
> --
> ---
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Paul Black" <paul_blac...@hotmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > Thanks Bob,

>
> > I amended your code slightly to get the number of the group at the
> > beginning and ended up with this :-

>
> > Public Sub Test()
> > Dim RowData As Range
> > Dim C As Long
> > Dim CombData As String
> > Dim CombNum As Integer

>
> > For Each RowData In Worksheets("Data").UsedRange.Rows
> > With RowData
> > If RowData.Row > 2 Then ' Combinations start in cell "B3"
> > CombNum = CombNum + 1
> > CombData = ""
> > For C = 1 To 5
> > CombData = CombData & .Cells(1, C).Value & ","
> > Next C
> > CombData = CombData & .Cells(1, 6).Value
> > Debug.Print "Set " & CombNum & "," & CombData
> > End If
> > End With
> > Next RowData

>
> > End Sub

>
> > Thanks Again.
> > All the Best.
> > Paul

>
> > On Aug 21, 11:26 am, "Bob Phillips" <bob....@somewhere.com> wrote:
> >> Public Sub Test()
> >> Dim RowData As Range
> >> Dim C As Long
> >> Dim CombData As String
> >> Dim CombNum As Integer

>
> >> For Each RowData In ActiveSheet.UsedRange.Rows
> >> With RowData
> >> If RowData.Row > 2 Then
> >> CombNum = CombNum + 1
> >> CombData = ""
> >> For C = 2 To 6
> >> CombData = CombData & .Cells(1, C).Value & ","
> >> Next C
> >> CombData = CombData & .Cells(1, 7).Value
> >> Debug.Print "Set " & CombNum & "," & CombData
> >> End If
> >> End With
> >> Next RowData
> >> End Sub

>
> >> --
> >> ---
> >> HTH

>
> >> Bob

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

>
> >> "Paul Black" <paul_blac...@hotmail.com> wrote in message

>
> >>news:(E-Mail Removed)...

>
> >> > Hi everyone,

>
> >> > I have the following code ...

>
> >> > Option Explicit
> >> > Option Base 1

>
> >> > Public Sub Test()
> >> > Dim RowData As Range
> >> > Dim C As Long
> >> > Dim CombData As String
> >> > Dim CombNum As Integer

>
> >> > CombNum = 1 <---------
> >> > For Each RowData In ActiveSheet.UsedRange.Rows
> >> > With RowData
> >> > If C > 0 Then CombNum = CombNum + 1
> >> > CombData = ""
> >> > For C = 1 To 5
> >> > CombData = CombData & .Cells(1, C).Value & ","
> >> > Next C
> >> > CombData = CombData & .Cells(1, 6).Value
> >> > Debug.Print "Set " & CombNum & "," & CombData
> >> > End With
> >> > Next RowData

>
> >> > End Sub

>
> >> > ... which does produce the right information in the right format.
> >> > I would like to amend the code to pick up the groups on a sheet named
> >> > "Groups" and in Cells "B3:G?". The groups could be 1 to whatever.
> >> > The other thing is that I have had to set the CombNum to 1 when I
> >> > think it should start at zero.
> >> > If there is a better way to code this I would appreciate any pointers.

>
> >> > Thanks in dvance.
> >> > All the Best.
> >> > Paul- Hide quoted text -

>
> >> - Show quoted text -- Hide quoted text -

>
> - Show quoted text -



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
amend a VB code please Morgan Microsoft Excel Misc 0 3rd Mar 2010 11:17 PM
Amend this Code-pls =?Utf-8?B?bXJiYWxhamU=?= Microsoft Outlook VBA Programming 1 11th Jun 2007 08:43 AM
How do I amend this code to ..... Mikey C Microsoft Excel Discussion 3 5th Apr 2007 11:58 AM
Insufficient pemissions to amend Excel files but can amend Word fi =?Utf-8?B?RiBMYXVmcw==?= Microsoft Windows 2000 Security 0 11th Oct 2006 12:28 PM
Amend the Code shan_in_dubai Microsoft Excel Programming 1 19th Jul 2005 09:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:20 AM.