473,395 Members | 1,441 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,395 software developers and data experts.

VBA in Excel

Currently I have a list of items in coulnm A in column H I have the quantity used and in coulmn E I have comma seperated values (could be 1 could be 30). I have created a Text-To-Columns action to move the info from column E to individual columns for example, if E2 had 3 comma seperated values the code takes these values splits them and moves them to seperate coulmns J, K and L within the same row. Here is the code just incase it brings value to my question. I also have a code that adds rows below based on the quantity count.
Expand|Select|Wrap|Line Numbers
  1. 'Separate the comma separated values into individual columns
  2.     Columns("E:E").Select
  3.     Selection.TextToColumns Destination:=Range("J1"), DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
  4.         Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
  5.         Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array _
  6.         (20, 1), Array(21, 1), Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), Array(28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1), Array( _
  7.         33, 1), Array(34, 1)), TrailingMinusNumbers:=True
Now, my problem.


I need to take these values from the columns (J, K and L) and move them to Cells E2, E3, and E4 I have the following code, but I am missing something becuase it is not working right.
Expand|Select|Wrap|Line Numbers
  1. 'Cut seperated values and paste in proper row
  2. i = 2
  3. j = 10
  4. Set CustTag = Cells(i, j)
  5.     Do While Not IsEmpty(CustTag)
  6.         t = CustTag.Value
  7.         l = CustTag.Column
  8.         If t > 0 Then
  9.             Range(t).Cut
  10.             Range("E" & i).Select
  11.             ActiveSheet.Paste
  12.             Set CustTag = CustTag.Offset(0, l + 1)
  13.         Else
  14.             Set CustTag = CustTag.Offset(0, 1)
  15.         End If
  16.     Loop
It is working on the first instance, then it stops... I hope it is an easy fix... any help?
Oct 9 '14 #1
3 3251
twinnyfo
3,653 Expert Mod 2GB
Insert between lines 15-16:

Expand|Select|Wrap|Line Numbers
  1. Set CustTag = Cells(i, j)
You have to Set CustTag to the new values of i and j.

However, as an overall advice, I would recommend splitting up your CSV using the Split() function will return an array. Then, instead of copying those values to other cells and then cutting and pasting back to different cells, just puts those values in the new rows you created (but did not show, because apparently your code works for that function).

But, if you can get this to work as is, no need to change anything.
Oct 9 '14 #2
twinnyfo
3,653 Expert Mod 2GB
But, I just noticed that you were doing that in line 12...........
Oct 9 '14 #3
twinnyfo
3,653 Expert Mod 2GB
Have you stepped through the cod eto see if it is looping through or does it just stop after the first iteration?

It looks like you are not incrementing i (to move to the next row) anywhere....
Oct 9 '14 #4

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

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
22
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
9
by: Anthony | last post by:
To me, creating Excel 2003 spreadsheets programmatically via VB.NET hasn't really changed since the days of VB6. That is, I'd do something similar to this Code: Dim ExcelApp As...
7
by: Alain \Mbuna\ | last post by:
Hi everybody. In my program I have some data that is calculated after some input from the user. I have written some code that opens an Excel workbook, with 5 worksheets and the calculated data...
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.