ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   insert two text values (https://www.excelbanter.com/excel-programming/306981-insert-two-text-values.html)

hotherps[_107_]

insert two text values
 
I have the following code that works well:

If .Cells(x, skilly).Value = "x" And did = False Then
For y = timeStart To timeStart + 7
If .Cells(x, y).Value = "." _
And counter < 6 _
And need 0 Then
.Cells(x, y).Value = "ENG"
counter = counter + 1
need = need - 1
End If
Next y
End If

What I want to is insert a text value "Test" into cells 7 and 8.
You can see the counter stops placing the value after 6 times I want t
fill in the next 2 cells after that with a fixed string value.The resul
would look like:

Eng Eng Eng Eng Eng Eng Test Test

Thank

--
Message posted from http://www.ExcelForum.com


Bob Kilmer

insert two text values
 
Cells(x, y).Resize(1, 6) = "ENG"
Cells(x, y + 6).Resize(1, 2) = "Test"

"hotherps " wrote in message
...
I have the following code that works well:

If .Cells(x, skilly).Value = "x" And did = False Then
For y = timeStart To timeStart + 7
If .Cells(x, y).Value = "." _
And counter < 6 _
And need 0 Then
Cells(x, y).Value = "ENG"
counter = counter + 1
need = need - 1
End If
Next y
End If

What I want to is insert a text value "Test" into cells 7 and 8.
You can see the counter stops placing the value after 6 times I want to
fill in the next 2 cells after that with a fixed string value.The result
would look like:

Eng Eng Eng Eng Eng Eng Test Test

Thanks


---
Message posted from http://www.ExcelForum.com/




Tom Ogilvy

insert two text values
 
Possibly

If .Cells(x, skilly).Value = "x" And did = False Then
For y = timeStart To timeStart + 7
If .Cells(x, y).Value = "." _
And counter <= 6 _
And need 0 Then
Cells(x, y).Value = "ENG"
Elseif Counter 6 then
Cells(x,y).Value = "ENG"
End if
counter = counter + 1
need = need - 1
End If
Next y
End If

However, if you will always fill in 8 cells then this might be easier:

If .Cells(x, skilly).Value = "x" And did = False and Need 0 and _
.Cells(x,TimeStart) = "." Then
.Cells(x,TimeStart).Resize(1,8).Value = _
Array("ENG","ENG","ENG","ENG","ENG","ENG","TEST"," TEST")
End if



--
Regards,
Tom Ogilvy

"hotherps " wrote in message
...
I have the following code that works well:

If .Cells(x, skilly).Value = "x" And did = False Then
For y = timeStart To timeStart + 7
If .Cells(x, y).Value = "." _
And counter < 6 _
And need 0 Then
Cells(x, y).Value = "ENG"
counter = counter + 1
need = need - 1
End If
Next y
End If

What I want to is insert a text value "Test" into cells 7 and 8.
You can see the counter stops placing the value after 6 times I want to
fill in the next 2 cells after that with a fixed string value.The result
would look like:

Eng Eng Eng Eng Eng Eng Test Test

Thanks


---
Message posted from http://www.ExcelForum.com/




hotherps[_108_]

insert two text values
 
Bob I got an unexpected result. Your code worked it dropped in "text" i
the two cells that it should have but after that it stopped followin
it's original criteria.

The part where it states the need 0 , it is ignoring because it keep
assigning Eng even after the need = 0

It's probably because I put it in the wrong place, did I?

With Sheet236
For x = 11 To 298
counter = 0
did = False
For n = 1 To timeStart
If .Cells(x, n).Value = "ENG" Then
did = True
End If
Next n
If .Cells(x, skilly).Value = "x" And did = False Then
For y = timeStart To timeStart + 7
If .Cells(x, y).Value = "." _
And counter < 6 _
And need 0 Then
.Cells(x, y).Value = "ENG"
counter = counter + 1
need = need - 1
Cells(x, y).Resize(1, 6) = "ENG"
Cells(x, y + 6).Resize(1, 2) = "Test"
End If
Next y
End If
Next x
End With

Thank

--
Message posted from http://www.ExcelForum.com


Bob Kilmer

insert two text values
 
What I tossed out was not a complete solution. I was just suggesting that
you can put values in more than one cell at a time. I didn't really work it
into your code. See Tom's comments.

"hotherps " wrote in message
...
Bob I got an unexpected result. Your code worked it dropped in "text" in
the two cells that it should have but after that it stopped following
it's original criteria.

The part where it states the need 0 , it is ignoring because it keeps
assigning Eng even after the need = 0

It's probably because I put it in the wrong place, did I?

With Sheet236
For x = 11 To 298
counter = 0
did = False
For n = 1 To timeStart
If .Cells(x, n).Value = "ENG" Then
did = True
End If
Next n
If .Cells(x, skilly).Value = "x" And did = False Then
For y = timeStart To timeStart + 7
If .Cells(x, y).Value = "." _
And counter < 6 _
And need 0 Then
Cells(x, y).Value = "ENG"
counter = counter + 1
need = need - 1
Cells(x, y).Resize(1, 6) = "ENG"
Cells(x, y + 6).Resize(1, 2) = "Test"
End If
Next y
End If
Next x
End With

Thanks


---
Message posted from http://www.ExcelForum.com/




Tom Ogilvy

insert two text values
 
Elseif Counter 6 then
Cells(x,y).Value = "ENG"


should have been

Elseif Counter 6 then
Cells(x,y).Value = "TEST"

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
Possibly

If .Cells(x, skilly).Value = "x" And did = False Then
For y = timeStart To timeStart + 7
If .Cells(x, y).Value = "." _
And counter <= 6 _
And need 0 Then
Cells(x, y).Value = "ENG"
Elseif Counter 6 then
Cells(x,y).Value = "ENG"
End if
counter = counter + 1
need = need - 1
End If
Next y
End If

However, if you will always fill in 8 cells then this might be easier:

If .Cells(x, skilly).Value = "x" And did = False and Need 0 and _
.Cells(x,TimeStart) = "." Then
.Cells(x,TimeStart).Resize(1,8).Value = _
Array("ENG","ENG","ENG","ENG","ENG","ENG","TEST"," TEST")
End if



--
Regards,
Tom Ogilvy

"hotherps " wrote in message
...
I have the following code that works well:

If .Cells(x, skilly).Value = "x" And did = False Then
For y = timeStart To timeStart + 7
If .Cells(x, y).Value = "." _
And counter < 6 _
And need 0 Then
Cells(x, y).Value = "ENG"
counter = counter + 1
need = need - 1
End If
Next y
End If

What I want to is insert a text value "Test" into cells 7 and 8.
You can see the counter stops placing the value after 6 times I want to
fill in the next 2 cells after that with a fixed string value.The result
would look like:

Eng Eng Eng Eng Eng Eng Test Test

Thanks


---
Message posted from http://www.ExcelForum.com/







All times are GMT +1. The time now is 03:01 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com