ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   do .... loop (https://www.excelbanter.com/excel-programming/312602-do-loop.html)

nhanh[_3_]

do .... loop
 

Hi,

I'm trying to use the Do loop in my coding but am getting no where.

I have already prompted the user with an input box asking for thei
name.

I have a list of names in sheet2
My aim is to start at the beginning of the list and move down th
column one cell at a time until i reach an empty cell. When I get t
the empty cell, i want input the new name that the user has jus
inputed.

Currently i have:


Public Sub AddNames()

Worksheets("Sheet1").Select
Range("B2").Select

Dim FirstName As String
FirstName = InputBox("What is your firstname?", "First Name")
ActiveWorkbook.Worksheets("sheet1").Range("B2").Va lue = FirstName

Dim SurName As String
SurName = InputBox("What is your surname?", "Surname Name")
ActiveWorkbook.Worksheets("sheet1").Range("B2").Of fset(0, 1).Value
SurName

Worksheets("Sheet2").Select
Range("A2").Select

Do Until IsEmpty(ActiveCell)

ActiveCell.Value = FirstName
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = SurName

Exit Do
Loop


I am sure there is something wrong with the coding after "D
Untill...". Any help would be REALLY appreciated. Thank

--
nhan
-----------------------------------------------------------------------
nhanh's Profile: http://www.excelforum.com/member.php...fo&userid=1501
View this thread: http://www.excelforum.com/showthread.php?threadid=26670


Don Guillett[_4_]

do .... loop
 
try this

Sub tt()
lastcell = Cells(Rows.Count, "a").End(xlUp).Row + 1
Cells(lastcell, "a").Value = InputBox("First Name")
Cells(lastcell, "a").Offset(, 1).Value = InputBox("last name")
End Sub

--
Don Guillett
SalesAid Software

"nhanh" wrote in message
...

Hi,

I'm trying to use the Do loop in my coding but am getting no where.

I have already prompted the user with an input box asking for their
name.

I have a list of names in sheet2
My aim is to start at the beginning of the list and move down the
column one cell at a time until i reach an empty cell. When I get to
the empty cell, i want input the new name that the user has just
inputed.

Currently i have:


Public Sub AddNames()

Worksheets("Sheet1").Select
Range("B2").Select

Dim FirstName As String
FirstName = InputBox("What is your firstname?", "First Name")
ActiveWorkbook.Worksheets("sheet1").Range("B2").Va lue = FirstName

Dim SurName As String
SurName = InputBox("What is your surname?", "Surname Name")
ActiveWorkbook.Worksheets("sheet1").Range("B2").Of fset(0, 1).Value =
SurName

Worksheets("Sheet2").Select
Range("A2").Select

Do Until IsEmpty(ActiveCell)

ActiveCell.Value = FirstName
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = SurName

Exit Do
Loop


I am sure there is something wrong with the coding after "Do
Untill...". Any help would be REALLY appreciated. Thanks


--
nhanh
------------------------------------------------------------------------
nhanh's Profile:

http://www.excelforum.com/member.php...o&userid=15019
View this thread: http://www.excelforum.com/showthread...hreadid=266706




kkknie[_207_]

do .... loop
 

Here's a diagnosis:

Worksheets("Sheet2").Select <-- Select Sheet2
Range("A2").Select <-- Select A2

Do Until IsEmpty(ActiveCell) <-- Do until A2 is empty

ActiveCell.Value = FirstName <-- Set A2 to FirstName
ActiveCell.Offset(0, 1).Select <-- Select B2
ActiveCell.Value = SurName <-- Set B2 to SurName

Exit Do
Loop

Don't see how you would ever exit here. Here is my thought
(untested):

If you want to enter it into the last available space, use this:

Range("A65536").End(xlUp).Offset(1,0).Value = FirstName
Range("A65536").End(xlUp).Offset(1,1).Value = SurName

If you are looking to add to the next available space (in column A)
use:

For Each r in Range("A1:A" & Range("A65536").End(xlUp).Row)
If r.Value = "" then
r.Value = FirstName
r.Offset(0,1).Value = SurName
Exit For
End If
Next

Sorry that I didn't do any testing, but I've got a new PC at home an
don't have Excel loaded yet. I'll check at work tomorrow (8am EST) t
see how things are going with your issue.



--
kkkni
-----------------------------------------------------------------------
kkknie's Profile: http://www.excelforum.com/member.php...nfo&userid=754
View this thread: http://www.excelforum.com/showthread.php?threadid=26670



All times are GMT +1. The time now is 11:57 PM.

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