473,396 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Excel input box to insert data into new excel row

Hello Everyone,

I am a novice to excel and VB. I want to make a program in an excel workbook that adds new client details to the workbook with an Input Box. So far I have achievded to add new client info bu it doesnt go to the new empty row below the last one I entered and I dont know why. All I wanted to do for the moment was to have client info be entered into the workbook but since I have column description at the top as well the information would have to be entered after the 11 row. I have been going at this for days now and cant figure out how to do it tried with For Next loop to add the info and a new column but doesnt work. Any help would be greatly appreciated.

I will paste the code I have so far here:
Expand|Select|Wrap|Line Numbers
  1. Sub Button1_Click()
  2. Dim emptyRow As Long
  3.  
  4. Dim i As Integer
  5. Dim n As Integer
  6. Dim m As Long
  7. Dim a As Integer
  8. 'Make Sheet2 Active
  9. Sheets(2).Activate
  10.  Dim lastrow As Range
  11.  Dim c As Integer
  12.  Dim ClientStat As String
  13.  Dim StrCustRef As String
  14.  Dim StrCompName As String
  15.  Dim ContactName As String
  16.  Dim Telephone As Single
  17.  Dim email As String
  18.  Dim ContDate As Date
  19.  Dim DateSentOffice As Date
  20.  Dim ClientReplyDate As Date
  21.  Dim ListSentDate As Date
  22.  Dim orders As String
  23.  Dim linkOrders As String
  24.  ClientStat = "ES"
  25.  n = ActiveCell.Row
  26.  lastrow = ActiveCell.Rows.Count
  27.  For i = n To lastrow
  28.  StrCustRef = InputBox("Please enter Customer Reference")
  29.  StrCompName = InputBox("Please Enter Company Name")
  30.  ContactName = InputBox("Please enter the name of the person you were in contact with")
  31.  Telephone = InputBox("Please enter client telephone Number")
  32.  email = InputBox("Please enter client email Adress")
  33.  ListSentDate = InputBox("Please Enter the Date the List and/or presentation were sent to the client")
  34.  ContDate = InputBox("Please enter the date when the client replyied to the presentation")
  35.  DateSentOffice = InputBox("Please enter the date the client request was sent to the office")
  36.  ClientReplyDate = InputBox("Please enter the date the client replied")
  37.  orders = InputBox("Orders Y/N")
  38.  Sheets("Sheet2").Range("A" & i) = ClientStat
  39.  Sheets("Sheet2").Range("B" & i) = StrCustRef
  40.  Sheets("Sheet2").Range("C" & i) = StrCompName
  41.  Sheets("Sheet2").Range("D" & i) = ContactName
  42.  Sheets("Sheet2").Range("E" & i) = Telephone
  43.  Sheets("Sheet2").Range("F" & i) = email
  44.  Sheets("Sheet2").Range("G" & i) = ContDate
  45.  Sheets("Sheet2").Range("H" & i) = DateSentOffice
  46.  Sheets("Sheet2").Range("I" & i) = ClientReplyDate
  47.  Sheets("Sheet2").Range("J" & i) = ListSentDate
  48.  Next i
  49. End Sub
It just doesnt go onto a new row when I enter new client information it just replaces the old one on top. I have another code as well:
Expand|Select|Wrap|Line Numbers
  1. Sub Button1_Click()
  2.     Dim emptyRow As Long
  3.  
  4.     Dim i As Integer
  5.     Dim n As Integer
  6.     Dim m As Long
  7.     Dim a As Integer
  8.      'Make Sheet2 Active
  9.     Sheets(2).Activate
  10.     Dim lastrow
  11.     Dim c As Integer
  12.     Dim ClientStat As String
  13.     Dim StrCustRef As String
  14.     Dim StrCompName As String
  15.     Dim ContactName As String
  16.     Dim Telephone As Single
  17.     Dim email As String
  18.     Dim ContDate As Date
  19.     Dim DateSentOffice As Date
  20.     Dim ClientReplyDate As Date
  21.     Dim ListSentDate As Date
  22.     Dim orders As String
  23.     Dim linkOrders As String
  24.     ClientStat = "ES"
  25.     With Worksheets("Sheet2")
  26.  
  27.         lastrow = .Range("A1").End(xlDown).Row
  28.  
  29.         StrCustRef = InputBox("Please enter Customer Reference")
  30.         StrCompName = InputBox("Please Enter Company Name")
  31.         ContactName = InputBox("Please enter the name of the person you were in contact with")
  32.         Telephone = InputBox("Please enter client telephone Number")
  33.         email = InputBox("Please enter client email Adress")
  34.         ListSentDate = InputBox("Please Enter the Date the List and/or presentation were sent to the client")
  35.         ContDate = InputBox("Please enter the date when the client replyied to the presentation")
  36.         DateSentOffice = InputBox("Please enter the date the client request was sent to the office")
  37.         ClientReplyDate = InputBox("Please enter the date the client replied")
  38.         orders = InputBox("Orders Y/N")
  39.         .Range("A" & lastrow) = ClientStat
  40.         .Range("B" & lastrow) = StrCustRef
  41.         .Range("C" & lastrow) = StrCompName
  42.         .Range("D" & lastrow) = ContactName
  43.         .Range("E" & lastrow) = Telephone
  44.         .Range("F" & lastrow) = email
  45.         .Range("G" & lastrow) = ContDate
  46.         .Range("H" & lastrow) = DateSentOffice
  47.         .Range("I" & lastrow) = ClientReplyDate
  48.         .Range("J" & lastrow) = ListSentDate
  49.         .Range("K" & lastrow) = orders
  50.     End With
  51. End Sub
Any help would be greatly appreciated.

Thanks
Aug 23 '11 #1
2 5388
Just Use Cells and manual looping, coz Range doesn't automatic

Expand|Select|Wrap|Line Numbers
  1. Dim i As Long, theCell As Long
  2.  
  3. For i = 11 To 100
  4.     If IsEmpty(ActiveSheet.Cells(i, 1).Value) = True Then
  5.         theCell = i
  6.         Exit For
  7.     End If
  8. Next
  9.  ActiveSheet.Cells(theCell, 1).Value = InputBox("Please enter Customer Reference", "Row " & theCell)
  10.  ActiveSheet.Cells(theCell, 2).Value = InputBox("Please enter the date the client replied", "Row " & theCell)
  11.  
Aug 24 '11 #2
Or you could do something like this

Expand|Select|Wrap|Line Numbers
  1. [A1].end(xldown).offset(1,0) = ClientStat
  2. [B1].end(xldown).offset(1,0) = StrCustRef
  3.  
etc...

or
Expand|Select|Wrap|Line Numbers
  1. [A1].end(xldown).offset(1,2) = StrCustRef
  2. [A1].end(xldown).offset(1,1) = StrCustRef
  3. [A1].end(xldown).offset(1,0) = ClientStat
  4.  
etc...
that should get you to the last row and you don't have to do any loops. Assuming that there aren't any blank cells between A1 and the end cell.
Aug 31 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: rked | last post by:
I get nameSPAN1 is undefined when I place cursor in comments box.. <%@ LANGUAGE="VBScript" %> <% DIM ipAddress ipAddress=Request.Servervariables("REMOTE_HOST") %> <html> <head> <meta...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
4
by: pshindle | last post by:
DB2 Team - I just downloaded and unzipped the new Fixpack 9 for DB2 ESE V8 for Windows (FP9_WR21350_ESE.exe). I then burned the unzipped Fixpack files to a CD. I proceded to install this...
1
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.