Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

The Offset property in VBA

Posted on 2004-03-21
2
Medium Priority
?
2,568 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
  • 2
2 Comments
 
LVL 81

Accepted Solution

by:
byundt earned 300 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

972 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