Solved

The Offset property in VBA

Posted on 2004-03-21
2
2,564 Views
Last Modified: 2012-06-21
I've working on a stock application and have written this code for a user form which adds new products to a sheet. The code I have for the form is as follows:

Private Sub Add_click()
Application.ScreenUpdating = False
StockList.Range("Newinfo").Select
Selection.EntireRow.Insert
StockList.Range("Newinfo").Offset(-1, 0).Value = Supplier.Value
StockList.Range("Newinfo").Offset(-1, 1).Value = Product_Name.Value
StockList.Range("Newinfo").Offset(-1, 2).Value = Order_Code.Value
StockList.Range("Newinfo").Offset(-1, 3).Value = Price.Value
StockList.Range("Newinfo").Offset(-1, 4).Value = Stock_Available.Value
Addprod.Hide
Application.ScreenUpdating = True
End Sub

I have five colomns on this sheet, and so I want data from each field on the form to go into one colomn respectively. The problem I'm having is that it enters the data right for all 5 (e.g. A20-E20), but then continues to insert data from the last field 'Stock_available' on the user form into F20-I20. Why Does it repeat the input just for the 'Stock_Available.Value'. Is there something wrong with this line:

StockList.Range("Newinfo").Offset(-1, 4).Value = Stock_Available.Value

Thanks in advance.
0
Comment
Question by:Bitemarx48
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 81

Accepted Solution

by:
byundt earned 75 total points
ID: 10645351
If Range("NewInfo") is bigger than a single cell, each of the offset instructions is trying to populate a range equivalent in size with the value.
Range"A1:A5").Offset(0,2)=1     'Fills C1:C5 with 1

If I understand your intent and if Range("NewInfo") refers to cells A21:E21, you could try the following:
StockList.Range("Newinfo").Offset(-1, 0)=Array(Supplier,Product_Name,Order_Code,Price,Stock_Available)
0
 
LVL 81

Expert Comment

by:byundt
ID: 10645711
Bitemarx48,
Welcome to Experts Exchange!

This question probably would probably have gotten answered quicker in the Excel TA, but thanks for the grade anyway.
Brad
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question