PC Review


Reply
Thread Tools Rate Thread

Do Loop and data formatting question

 
 
B~O~B
Guest
Posts: n/a
 
      11th Jul 2008
First I am getting a file and all the data is text. Is there a way to
convert the Text to Numbers?

What I am trying to do is generate a indented Bill of Material. The
report I received has levels in Column "B". I would like to indent the
cell in column "B" based on the level that the item report to. I am
trying to do a conditional do loop but I am get error with the
"Selection.InsertIndent 1". I have also added a X=Abs(Range("B" &
i).Select) or something to this affect and did a
Selection.InsertIndent X to try and keep the coding simple to no
luck.. Can someone help?



i = 4
Do
Range("B" & i).Select
If Range("B" & i).Select = -1 Then
Selection.InsertIndent 1
Else
Selection.InsertIndent 4
i = i + 1
End If
Loop Until IsEmpty(ActiveCell.Offset(0, 1))
End Sub
 
Reply With Quote
 
 
 
 
Mike
Guest
Posts: n/a
 
      11th Jul 2008
You shouldn't have to select the cells. Try this
Sub loop()
i = 4
Do While Len(Range("B" & i).Formula) > 0
If Range("B" & i).Value = -1 Then
Range("B" & i).InsertIndent 1
Else
Range("B" & i).InsertIndent 4
End If
i = i + 1
Loop
End Sub

"B~O~B" wrote:

> First I am getting a file and all the data is text. Is there a way to
> convert the Text to Numbers?
>
> What I am trying to do is generate a indented Bill of Material. The
> report I received has levels in Column "B". I would like to indent the
> cell in column "B" based on the level that the item report to. I am
> trying to do a conditional do loop but I am get error with the
> "Selection.InsertIndent 1". I have also added a X=Abs(Range("B" &
> i).Select) or something to this affect and did a
> Selection.InsertIndent X to try and keep the coding simple to no
> luck.. Can someone help?
>
>
>
> i = 4
> Do
> Range("B" & i).Select
> If Range("B" & i).Select = -1 Then
> Selection.InsertIndent 1
> Else
> Selection.InsertIndent 4
> i = i + 1
> End If
> Loop Until IsEmpty(ActiveCell.Offset(0, 1))
> End Sub
>

 
Reply With Quote
 
B~O~B
Guest
Posts: n/a
 
      12th Jul 2008
On Jul 11, 4:24*pm, Mike <M...@discussions.microsoft.com> wrote:
> You shouldn't have to select the cells. Try this
> Sub loop()
> * * i = 4
> * * Do While Len(Range("B" & i).Formula) > 0
> * * If Range("B" & i).Value = -1 Then
> * * *Range("B" & i).InsertIndent 1
> * * Else
> * * *Range("B" & i).InsertIndent 4
> * * End If
> * * i = i + 1
> * * Loop
> End Sub
>
>
>
> "B~O~B" wrote:
> > First I am getting a file and all the data is text. *Is there a way to
> > convert the Text to Numbers?

>
> > What I am trying to do is generate a indented Bill of Material. *The
> > report I received has levels in Column "B". I would like to indent the
> > cell in column "B" based on the level that the item report to. *I am
> > trying to do a conditional do loop but I am get error with the
> > "Selection.InsertIndent 1". * I have also added a X=Abs(Range("B" &
> > i).Select) or something to this affect and did a
> > Selection.InsertIndent X to try and keep the coding simple to no
> > luck.. *Can someone help?

>
> > i = 4
> > * * Do
> > * * Range("B" & i).Select
> > * * If Range("B" & i).Select = -1 Then
> > * * Selection.InsertIndent 1
> > * * Else
> > * * Selection.InsertIndent 4
> > * * i = i + 1
> > End If
> > * * Loop Until IsEmpty(ActiveCell.Offset(0, 1))
> > End Sub- Hide quoted text -

>
> - Show quoted text -


No luck... I get a syntax error with the "Sub Loop()" if i remove it
then the macro does noting...
 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      12th Jul 2008
sorry bob try this
Sub test()
i = 4
Do While Len(Range("B" & i).Formula) > 0
If Range("B" & i).Value = -1 Then
Range("B" & i).InsertIndent 1
Else
Range("B" & i).InsertIndent 4
End If
i = i + 1
Loop
End Sub

"B~O~B" wrote:

> On Jul 11, 4:24 pm, Mike <M...@discussions.microsoft.com> wrote:
> > You shouldn't have to select the cells. Try this
> > Sub loop()
> > i = 4
> > Do While Len(Range("B" & i).Formula) > 0
> > If Range("B" & i).Value = -1 Then
> > Range("B" & i).InsertIndent 1
> > Else
> > Range("B" & i).InsertIndent 4
> > End If
> > i = i + 1
> > Loop
> > End Sub
> >
> >
> >
> > "B~O~B" wrote:
> > > First I am getting a file and all the data is text. Is there a way to
> > > convert the Text to Numbers?

> >
> > > What I am trying to do is generate a indented Bill of Material. The
> > > report I received has levels in Column "B". I would like to indent the
> > > cell in column "B" based on the level that the item report to. I am
> > > trying to do a conditional do loop but I am get error with the
> > > "Selection.InsertIndent 1". I have also added a X=Abs(Range("B" &
> > > i).Select) or something to this affect and did a
> > > Selection.InsertIndent X to try and keep the coding simple to no
> > > luck.. Can someone help?

> >
> > > i = 4
> > > Do
> > > Range("B" & i).Select
> > > If Range("B" & i).Select = -1 Then
> > > Selection.InsertIndent 1
> > > Else
> > > Selection.InsertIndent 4
> > > i = i + 1
> > > End If
> > > Loop Until IsEmpty(ActiveCell.Offset(0, 1))
> > > End Sub- Hide quoted text -

> >
> > - Show quoted text -

>
> No luck... I get a syntax error with the "Sub Loop()" if i remove it
> then the macro does noting...
>

 
Reply With Quote
 
B~O~B
Guest
Posts: n/a
 
      14th Jul 2008
On Jul 12, 1:41*pm, Mike <M...@discussions.microsoft.com> wrote:
> sorry bob try this
> Sub test()
> * * i = 4
> * * Do While Len(Range("B" & i).Formula) > 0
> * * If Range("B" & i).Value = -1 Then
> * * *Range("B" & i).InsertIndent 1
> * * Else
> * * *Range("B" & i).InsertIndent 4
> * * End If
> * * i = i + 1
> * * Loop
> End Sub
>
>
>
> "B~O~B" wrote:
> > On Jul 11, 4:24 pm, Mike <M...@discussions.microsoft.com> wrote:
> > > You shouldn't have to select the cells. Try this
> > > Sub loop()
> > > * * i = 4
> > > * * Do While Len(Range("B" & i).Formula) > 0
> > > * * If Range("B" & i).Value = -1 Then
> > > * * *Range("B" & i).InsertIndent 1
> > > * * Else
> > > * * *Range("B" & i).InsertIndent 4
> > > * * End If
> > > * * i = i + 1
> > > * * Loop
> > > End Sub

>
> > > "B~O~B" wrote:
> > > > First I am getting a file and all the data is text. *Is there a way to
> > > > convert the Text to Numbers?

>
> > > > What I am trying to do is generate a indented Bill of Material. *The
> > > > report I received has levels in Column "B". I would like to indent the
> > > > cell in column "B" based on the level that the item report to. *Iam
> > > > trying to do a conditional do loop but I am get error with the
> > > > "Selection.InsertIndent 1". * I have also added a X=Abs(Range("B" &
> > > > i).Select) or something to this affect and did a
> > > > Selection.InsertIndent X to try and keep the coding simple to no
> > > > luck.. *Can someone help?

>
> > > > i = 4
> > > > * * Do
> > > > * * Range("B" & i).Select
> > > > * * If Range("B" & i).Select = -1 Then
> > > > * * Selection.InsertIndent 1
> > > > * * Else
> > > > * * Selection.InsertIndent 4
> > > > * * i = i + 1
> > > > End If
> > > > * * Loop Until IsEmpty(ActiveCell.Offset(0, 1))
> > > > End Sub- Hide quoted text -

>
> > > - Show quoted text -

>
> > No luck... *I get a syntax error with the "Sub Loop()" if i remove it
> > then the macro does noting...- Hide quoted text -

>
> - Show quoted text -


Mike,

If worked. Thanks all you help.
 
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
Loop QUESTION to end of data range... mniccole Microsoft Excel Worksheet Functions 2 4th Dec 2006 09:25 PM
Loop QUESTION to end of data range... mniccole Microsoft Excel Worksheet Functions 2 4th Dec 2006 05:19 PM
Loop QUESTION to end of data range... mniccole Microsoft Excel Worksheet Functions 0 4th Dec 2006 03:59 PM
VBA Loop Formatting Text Question =?Utf-8?B?UmljaGFyZA==?= Microsoft Excel Programming 3 13th Jun 2006 05:08 PM
Data formatting question Jim Short Microsoft Excel Discussion 2 16th Mar 2004 02:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:38 AM.