Solved

The Offset property in VBA

Posted on 2004-03-21
2
2,563 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

762 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